I saw the following source code in someone’s repository:
module Twitter
module Bootstrap
module Rails
require 'twitter/bootstrap/rails/engine' if defined?(Rails)
end
end
end
require 'less-rails'
require 'twitter/bootstrap/rails/bootstrap' if defined?(Rails)
I want to know what’s difference when we put require in a module?
There is no difference as far as the
requireis concerned, i.e.,requirealways loads the file into the global namespace.It should be noted that, in this case, the inner
requirewill always run, sinceRailsat that point refers to the module it is within, so theifstatement there will always evaluate to true.This means the code is equivalent to the possibly less confusing: