How to run Ruby code from terminal?

Andresh Podzimovsky picture Andresh Podzimovsky · Sep 12, 2012 · Viewed 155.5k times · Source

I need to run a few lines of Ruby code from terminal, but I can't find the needed parameter for it.

Can you explain how to do this?

Answer

theglauber picture theglauber · Sep 12, 2012

If Ruby is installed, then

ruby yourfile.rb

where yourfile.rb is the file containing the ruby code.

Or

irb

to start the interactive Ruby environment, where you can type lines of code and see the results immediately.