This is the old RCRchive. It's available only for
reading and reference. To submit RCRs for Ruby 1.9/2.0, and to participate
in discussions about them, please visit
the new RCRchive.
RCR 341: Let Kernel#require take multiple arguments
Submitted by rixxon
(Thu Jul 13 01:30:08 UTC 2006)
Abstract
Let Kernel#require try to load all the specified libraries.
Problem
Kernel#require can only load one library per call. So either we write several require calls,
require 'foo'
require 'bar'
require 'xyzzy'
or iterate an array of libraries (doesn't work too well with rdoc),
%w[foo bar xyzzy].each {|lib| require lib }
Although this works fine, it feels natural that require should be able to take multiple arguments. In Python for example, it is perfectly valid to
import foo, bar, xyzzy
Proposal
My proposal is simple:
require 'foo', 'bar', 'xyzzy'
which will also make this possible,
require %w[foo bar xyzzy]
I think this leads to cleaner syntax; you can load multiple libraries on a single line without resorting to iterators.
Analysis
Would not break backwards compatibility.
Implementation
module Kernel
alias :old_require :require
def require(*libs)
libs.each {|lib| old_require lib }
end
end
Sounds good to me, i am in favor of it.
Btw I currently also use this way to require multiple files:
%w(
cgi
fileutils
yaml
socket
webrick
).each { |x| require x }
"doesn't work too well with rdoc"
The problem with rdoc is a problem which rdoc needs to
fix in my humble opinion. I feel that rdoc should be
made smarter or more flexible.
If i for example have a line with
- =================== #
rdoc gets confused by it as well, even though the ruby
parser handles it like what it is - a simple comment.
Maybe other people'd have comments to improve rdoc
as well but lets keep it to the RCR about
extending Kernel#require :)
Oops... even here the wiki markup is confused about it ... just think that the above line starts with an #, then has some ==, then an ending # again ... :P
|
| Strongly opposed | 0 |
| Opposed | 2 |
| Neutral | 3 |
| In favor | 2 |
| Strongly advocate | 3 |
|
RCRchive copyright © David Alan Black, 2003-2005.
Powered by Ruby on Rails.
Btw I currently also use this way to require multiple files:
%w( cgi fileutils yaml socket webrick ).each { |x| require x }
"doesn't work too well with rdoc"
The problem with rdoc is a problem which rdoc needs to fix in my humble opinion. I feel that rdoc should be made smarter or more flexible. If i for example have a line with
- =================== #
rdoc gets confused by it as well, even though the ruby parser handles it like what it is - a simple comment. Maybe other people'd have comments to improve rdoc as well but lets keep it to the RCR about extending Kernel#require :)Oops... even here the wiki markup is confused about it ... just think that the above line starts with an #, then has some ==, then an ending # again ... :P