Reputation: 15404
I am new to Ruby and am learning from this tutorial on the Ruby site.
I can run simple scripts from the IRB command line but I am not sure how to run a script I have written on an external .rb
file.
Is there a special directory I must put this in to run it from IRB?
Upvotes: 0
Views: 603
Reputation: 1249
eval(File.read 'your_script.rb')
no special directory, just make sure to use correct path
Upvotes: 1
Reputation: 8999
Use require './filename.rb'
. For example:
06:34:38 ~$ echo "puts 'asdf'" > foo.rb
06:34:55 ~$ irb
2.0.0p247 :001 > require './foo.rb'
asdf
=> true
2.0.0p247 :002 >
Upvotes: 1
Reputation: 12826
You should not run scripts in files using IRB. Exit the IRB and run:
ruby some_path/some_script.rb
Upvotes: 2