Zhao Yi wrote:
> If there are some variables defined in a module which is included by
> more than one files, there will be a warning indicating "warning:
> already initialized". If ruby only imports once, why such warning is
> thrown?
I don't know about all cases but I suspect the biggest culprit is require 'foo'
twice with different paths.
If you have a Rails project, it has a Magic Loader that automagically loads the
file foo.rb if the interpreter sees a Foo reference and has not seen a
definition for Foo yet. This is a miracle and a pain in the butt, because a
subsequent require 'foo' line might not have the same path, and you get the
double-require issue.
If the problem persists, given a warning on Bar, write:
unless defined? Bar
Bar = 42 # or whatever
end
That's a total hack, but it works well enough.
--
Phlip