Reputation: 2171
There seems to be two types of classes in ruby, one type I don't need to require they're always accessible (like Float, Array, Hash, etc.). They are a part of ruby and this is expected.
But there are also some constants that are not accessible unless explicitly required (like REXML, Observable, YAML). They are part of Ruby too and I would expect to be able to access them without require.
Why these constants are not available without require?
In Rails guides it is not recommended to explicitly require anything as this messes up Rails autoload mechanism. If these constants need to be required anyway, what is the best way to do it?
Should I use require or require_dependency?
Should I use require at the top of the file where the constant is used or should I do it globally somehow?
EDIT: Also, since constants availability depends on the loading order it is easy to forget to require some file and it will not break until load order changes somehow. What is the best way to not face such error except being extra alert about every constant you use?
Upvotes: 2
Views: 275
Reputation: 230276
There are two kinds of things that are "built-in".
If these constants need to be required anyway, what is the best way to do it?
If you don't monkeypatch them, then you just go ahead and require them whereever you want. I normally do it at the top of the file where they are used.
If you do monkeypatch them, I suggest you reconsider. :)
Upvotes: 2