Overview
It is possible to run a ruby code directly on a command line or the terminal itself. We need to pass the -e flag. This is the syntax for the same
ruby -e "<ruby_code>"
Program
Below is one simple example
ruby -e "puts 'hello'"
Run the above command on the terminal and it will give the output
hello
How to run the multiline ruby code. Below is an example of the same. You don’t need to use -e flag.
ruby <<END
puts "Start"
5.times do |i|
puts i
end
puts "End"
END
The above program will output
Start
0
1
2
3
4
End