Hi.

I would like to know how I could save one line of code.

Situation right now:

  require 'evil_module'

  class Foo
    include EvilModule
  end

Everyone knows this, this works fine.

However, what I now want to do is, use only require,
and have this module included into ALL classes of
the .rb file. In other words:


  require 'evil_module'

  class Foo
  end

Should become the same as the above.

But only in .rb files from where the require is used.

Is this possible? I was told it may be possible via
the required hook, but it would require changing
modules globally (monkey patch), which I absolutely
would not want to do.

The reason why I need this, before anyone asks:

I have a global colourizer method, which I use
for ALL my ruby projects and all my ruby classes,
but optionally. I.e. I want to toggle and control
whether to use ansicolours or not.

The current code I have requires me to use an
explicit include, which is ok, but I'd rather
be able to eliminate one line of code, which
would in turn eliminate around 3000 lines of
code (the amount of classes I wrote in ruby so
far).

-- 
Posted via http://www.ruby-forum.com/.