I’d like to know your motivation. Why do you want it to
auto-include the module? Or, more importantly: why do you
want it to be in a module?
As I wrote before:
-> I would like to have this as I could eliminate a lot of
lines of include code.
there’s no practical way to have an include-on-require trigger,
because there is no rule that says how many modules are defined
in a given source file, or what they might be called, or whether
they might not be reopened pre-existing modules, etc.
But I know what rules should be defined. I would like this
to be valid only for when I require something in a given .rb
file. In other words, I would like to have functionality like
“I want to require a certain module, but only into a specific
class”. This is possible in ruby when you use require, and
then include, but it seems as if I can not combine the two
in one line. I think python allows more power upon require/import
time than ruby here.
A more advanced Example I would like to aim for:
Consider a file ‘foo.rb’
Now I have a module called ‘bar.rb’
def test; puts ‘hi from test, defined in module Bar’;end
Currently I would have to do this in file ‘foo.rb’:
The layout of my projects is always the same, so in all examples
like the above, the explicit include Bar lines are superfluous
and unnecessary to me.
My idea would be to allow something like this:
include Bar # <— and this here would be automatic
In other words, it would allow me to do auto-include on
Is this possible somehow?
It seems that the best I can do is to include a module
upon require time but only into the general top scope
namespace (the explicit include Bar in file bar.rb).