Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Ruby code from terminal?

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?

like image 893
Andresh Podzimovsky Avatar asked Sep 11 '12 22:09

Andresh Podzimovsky


People also ask

How do I run Ruby on Mac terminal?

Open Interactive Ruby If you're using macOS open up Terminal and type irb, then hit enter. If you're using Linux, open up a shell and type irb and hit enter. If you're using Windows, open Interactive Ruby from the Ruby section of your Start Menu.

How do I run a Ruby file in terminal Windows?

In this case, it's a Ruby file to be executed with the Ruby interpreter. To mark the file as executable, run the command chmod +x test. rb. This will set a file permission bit indicating that the file is a program and that it can be run.

How do I run Ruby shell?

You can start it by typing irb in your shell and hitting enter. Its name is short for “Interactive Ruby Shell”, and yes, it is another kind of shell: Just like the shell running in your terminal irb is also a program that interactively waits for you to type something, and hit enter.


1 Answers

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.

like image 148
theglauber Avatar answered Sep 18 '22 07:09

theglauber