Thursday, September 10, 2009

How to Run (Load) a .rb (Ruby) Script in Rails

If you don't need Rails, you can just run a Ruby script at command-line:
ruby path/to/file/some_script.rb

But if your script requires to be run in your Rails project environment:

cd (root of rails project)
script/console
load 'path/to/file/some_script.rb'

Load will execute the script every time you do the load, unlike require which will only run it once (and for require you remove the .rb extension at the end of the filename).

See also:
* http://www.fromjavatoruby.com/2008/10/require-vs-load.html

No comments: