Execute Ruby Program

Generally there are two ways of execute ruby program.

  • Interactive Ruby Cell
  • With ruby command

Interactive Ruby Cell (irb): Interactive Ruby Shell (IRB or irb) is a REPL for programming in the object-oriented scripting language Ruby. For this:

  1. Open terminal.
  2. Use irb command to open it. Which will open sell script to execute ruby program.

Ruby Command: The extension of ruby file is .rb . Write ruby program to any file with extension with .rb called main.rb. In terminal, change the directory in which ruby file exists and run ruby program with following command.

main.rb

$ruby main.rb

Here you can see the output of your program.

0Shares