Not at all. This is what require is for. If you don't require a file,
it won't be read.
Mike's point is, that if you require a library which requires other
files in turn you might end up loading 50 files although you just need 3
of them. That overhead can be significant for short lived programs.
He has a valid point: basically his question is, how do I declare file
dependencies in complex libraries without immediately "executing" them
(means: reading all those files)? A good approach here is to use
autoload alone or a combination of autoload and require as I have done
in the Muppet Laboratories project (see link below).
Autoload just automates require AFAIK.
Yes, but this is crucial here: autoload will require a file once a
constant is accessed the first time. And you can even nest it, i.e. use
it inside a module. That way, if a class is never used at all, you
won't read that file.
You can find an example in my project:
http://github.com/rklemme/muppet-laboratories/blob/master/lib/animal.rb
Of course you can! Why do you think you can't?
Exactly. The required file can contain anything - from zero to multiple
classes.
If you wrap it in a class or module, you get to specify the scope.
Hmm... I am not aware of any scoping issues right now but you could
avoid them by anchoring the class name:
class ::Foo
end
That class is always defined in the root namespace.
Kind regards
robert