Kernel#require accepting multiple arguments?

D

Daniel Schierbeck

What is the reason that Kernel#require only accepts one filename?
Implementing a version of `require' that can take multiple arguments is
pretty easy:

module Kernel
alias_method :__require__, :require

def require(*filenames)
filenames.all? { |file| __require__(file) }
end
end


Cheers,
Daniel
 
S

Stefan Lang

What is the reason that Kernel#require only accepts one filename?
Implementing a version of `require' that can take multiple
arguments is pretty easy:

module Kernel
alias_method :__require__, :require

def require(*filenames)
filenames.all? { |file| __require__(file) }
end
end

Perhaps to allow version specification in the future.
E.g.:

require 'foo', '>= 1.0.1'

like RubyGems require_gem.

Regards,
Stefan
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Kernel#require accepting multiple arguments?"

|What is the reason that Kernel#require only accepts one filename?

Since we'd like to keep it for "parametrized require" in the future.

matz.
 
D

Daniel Schierbeck

Yukihiro said:
Hi,

In message "Re: Kernel#require accepting multiple arguments?"

|What is the reason that Kernel#require only accepts one filename?

Since we'd like to keep it for "parametrized require" in the future.

matz.

Good enough for me!


Cheers,
Daniel
 
E

Eric Hodel

What is the reason that Kernel#require only accepts one filename?
Implementing a version of `require' that can take multiple
arguments is pretty easy:

module Kernel
alias_method :__require__, :require

def require(*filenames)
filenames.all? { |file| __require__(file) }
end
end

Or you can turn the problem around:

%w[file1 file2].each { |f| require f }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top