When running ruby scripts as such
ruby some-script.rb
How would I include a file (e.g. configuration file) in it dynamically?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As you have found, the -r option is your friend. It also works with IRB:
Will do the same as
require 'open-uri'FWIW, the most common thing I need to include via the command line is rubygems. And since newer versions of ruby come with gems built in I don’t want to edit the file, but include it for testing. Luckily the folks who created gems added a little alias sugar.
You can do the following:
Instead of the ugly:
OK, so it is one character, but thought it was extra polish to make me happier.