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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top