How to run Ruby code from a terminal?

I need to run a few lines of Ruby code from the terminal, but I cannot find the required parameter for it.

Can you explain how to do this?

+74
ruby terminal console
Sep 11 '12 at 22:24
source share
2 answers

If Ruby is installed, then

ruby yourfile.rb 

where yourfile.rb is the file containing the ruby โ€‹โ€‹code.

or

 irb 

to launch an interactive Ruby environment where you can type lines of code and see results immediately.

+132
Sep 11 '12 at 22:26
source share

You can run ruby โ€‹โ€‹commands on the same line with the -e flag:

 ruby -e "puts 'hi'" 

See the man page for more information.

+34
Sep 11 '12 at 22:28
source share



All Articles