How to execute a Ruby script in Terminal? How to execute a Ruby script in Terminal? ruby ruby

How to execute a Ruby script in Terminal?


Just call: ruby your_program.rb

or

  • start your program with #!/usr/bin/env ruby,
  • make your file executable by running chmod +x your_program.rb
  • and do ./your_program.rb some_param


Open your terminal and open folder where file is saved.
Ex /home/User1/program/test.rb

  1. Open terminal
  2. cd /home/User1/program
  3. ruby test.rb

format or test.rb

class Test   def initialize   puts "I love India"  endend# initialize objectTest.new

output

I love India


Assuming ruby interpreter is in your PATH (it should be), you simply run

ruby your_file.rb