Ruby: how to require a file from the current working dir?
In ruby 1.9.x, you can use the method require_relative
. See http://www.ruby-doc.org/core-1.9.3/Kernel.html#method-i-require_relative.
Best way to require all files from a directory in ruby?
How about:
Dir["/path/to/directory/*.rb"].each {|file| require file }
Cleanest/One-liner way to require all files in directory in Ruby?
project_root = File.dirname(File.absolute_path(__FILE__))
Dir.glob(project_root + '/helpers/*') {|file| require file}
Or to golf it a bit more:
Dir.glob(project_root + '/helpers/*', &method(:require))
Related Topics
How to Return Something Early from a Block
Where in the Ruby Language Is %Q, %W, etc., Defined
Finding the Session Id in Rails 3
What Does "Wrong Number of Arguments (1 for 0)" Mean in Ruby
How to Set an Option as Selected Using Selenium Webdriver (Selenium 2.0) Client in Ruby
Ruby To_JSON Issue with Error "Illegal/Malformed Utf-8"
How to Use the Rails Helper "Distance_Of_Time_In_Words" in Plain Old Ruby (Non-Rails)
Why Is Ruby Unable to Verify an Ssl Certificate
Cannot Execute "Rails Console" Due to an Error with Readline
When to Use Curly Braces VS Parenthesis in Expect Rspec Method
Extracting the Last N Characters from a Ruby String
Get Class Location from Class Object
How to Install Nokogiri Ruby Gem with Mkmf.Log Saying Libiconv Not Found