tags:

views:

39

answers:

2

if i have a.rb:

require 'rack'
require 'b'

and my b.rb is:

//do something with rack

Does b.rb need to also say:

require 'rack'

if b.rb will only ever be 'require'd by a.rb?

I'm seeing a lot of code where a.rb requires 'rack' and includes b.rb which also requires 'rack'.

+1  A: 

If you can guarantee that rack will always have been required before b is required, then there is no need to require 'rack' inside b.rb. This can cause problems if you ever reorganize your code to require things in a different order, however.

Greg Campbell
A: 

Try:

require 'rack' if defined?(Rack).nil?

This just tests to see if the constant for Rack, which is a module, is defined and requires it if the constant is nil.

The Wicked Flea