From: Jesse Merriman Date: 2007-06-11T05:33:58+09:00 Subject: Re: Requiring more than one file? On Sunday 10 June 2007 15:24, Marc Heiler wrote: > require does accept ony word, which should be the name that has > to be required. Since duck typing is en vogue, is it a bad idea to > have require use something like this here instead? > > require %w( pp English pathname fileutils abbrev pp digest/md5 yaml) > > The reason I write this is because I quite often see this: > > %w( pathname fileutils English abbrev pp digest/md5 yaml ).each { |file| > require file } > > which some people like to do compared to the a little cumbersome: > > require 'pathname' > require 'fileutils' > require 'English' > require 'abbrev' > > Is there a reason why require accepts only one arg, and why it doesnt > allow multiple args/Array as arg? > You can always do something like this: $ cat foo.rb def foo; puts 'foo'; end $ cat bar.rb def bar; puts 'bar'; end $ irb irb(main):001:0> module Kernel irb(main):002:1> alias :require_orig :require irb(main):003:1> def require *args irb(main):004:2> args.each { |a| require_orig(a) } irb(main):005:2> end irb(main):006:1> end => nil irb(main):009:0> require 'foo', 'bar' => ["foo", "bar"] irb(main):010:0> foo foo => nil irb(main):011:0> bar bar => nil -- Jesse Merriman jessemerriman@warpmail.net http://www.jessemerriman.com/