I've been looking at the Ruby Standard Library Documentation for 1.9.3. I'm wondering how I can find out which libraries I need to explicitly require.
For example, I have been told I need to explicitly require the json library, but not rubygems, although they both appear in the standard library list.
Is there another place I can look for information about the requirements, or even a pry/irb command I can run to see what is already 'required'?
Every library has to be required/loaded, if you want to use it.
Performance-wise, require is smart and will not load libraries if they're already loaded.
However, if you want to check if a library is required you should see the top-level namespace it defines and check if this is defined in your current scope. For example open an IRB session and do:
defined? JSON # => nil (it's not loaded)
require 'json' # => true (load it)
defined? JSON # => "constant" (it's loaded)
require 'json' # => false (it's already loaded, so it's not loaded it again)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With