Best way to require all files from a directory in ruby? Best way to require all files from a directory in ruby? ruby ruby

Best way to require all files from a directory in ruby?


How about:

Dir["/path/to/directory/*.rb"].each {|file| require file }


If it's a directory relative to the file that does the requiring (e.g. you want to load all files in the lib directory):

Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }

Edit: Based on comments below, an updated version:

Dir[File.join(__dir__, 'lib', '*.rb')].each { |file| require file }