Enable ruby ​​guard

What is the idiomatic way to add an inclusion protector to a ruby ​​file, similar

#ifdef FOO_H
#define FOO_H
...

#endif

in C?

+3
source share
2 answers

As Chris Jet-Young says, it requireshould be all you need. However, you can use a simple ifor “turn on” protector if you want to make it one, for example:

unless defined? FooGuard
  FooGuard = true
  ... rest of code ...
end

You can do anything in the body if, including defining classes, methods, etc.

+6
source

require, ( , /), Ruby .

+11

Source: https://habr.com/ru/post/1712470/


All Articles