From: Gennady Bystritsky Date: 2008-04-30T02:07:48+09:00 Subject: Re: "require" with many files Iņaki Baz Castillo wrote: > Hi, is there any preferred way to load/require all the fiels > in a directory? > For example, my main file does: > > require "header.rb" > > and file "header.rb" must load all the related files contained in > "headers/" directory. I do the following in "header.rb": > > headers_path = File.dirname(__FILE__) + '/headers' > Dir.chdir(headers_path) Dir["*.rb"].each do |file| > require "#{headers_path}/#{file}" > end > > Is it enought ok or can it receive some Ruby's magic? XD > > Thanks for any suggestion. You do use Ruby magic here ;-). The only thing I would suggest is that if you do not have to set the current directory to headers_path for some other reason, use this variation: Dir[File.join(File.dirname(__FILE__), 'headers', "*.rb")].each do |file| require file end Gennady.