Require returns an array instead of a boolean

According to the documentation for Kernel # require, the method returns a boolean value. I noticed in an IRB session, however, require returns an array for some files.

 ruby-1.8.7-p330 :001 > require 'net/http' => true ruby-1.8.7-p330 :002 > require 'date' => true ruby-1.8.7-p330 :003 > require 'lib/data_provider' => ["DataProviders"] 

The returned array contains the name of the module defined in data_provider.rb:

 module DataProviders module Cached class Foo # ... end end class Foo # ... end end 

Is this a sign that I'm doing something wrong or some kind of undocumented require behavior?

+7
source share
1 answer

I also can not reproduce it. But it is possible that some kind of pearl redefines Kernel#require :

 module Kernel alias_method :old_require, :require def require(str) old_modules = [] ObjectSpace.each_object(Module) {|m| old_modules << m } old_require(str) new_modules = [] ObjectSpace.each_object(Module) {|m| new_modules << m unless old_modules.include?(m) } new_modules end end 

and when trying to demand

 module DataProviders module Cached class Foo end end class Foo end end 

You'll get

 irb(main):012:0> require 'data_provider' => [DataProviders::Cached::Foo, DataProviders::Foo, DataProviders::Cached, DataProviders] 
+2
source

All Articles