Putting Ruby code in a file is obviously far more convenient and practical than using multiple -e command-line options. However, suppose we want to go a step further and be able to run a Ruby-based program by typing the file name containing the code rather than the ruby command.
On Linux or UNIX, this is accomplished by including a special line at the top of the script file that instructs the environment responsible for executing the ruby program(such as a Linux command shell) to look for the Ruby interpreter. This special line, commonly known as the ‘shebang’, consists of a ‘#’, a ‘!’, and the path to the ruby executable.
We will modify the ruby file ‘SimpleExample.rb’ accordingly:
#!/usr/bin/ruby
puts "Hello Ninjas! Please look forward to learn more.\n"
puts "I hope you're enjoying it!\n"
You can also try this code with Online Ruby Compiler
Run Code
We have covered the most simple Ruby examples to learn Ruby in an easier way. Hopefully, you learned alongside us and have a clear understanding!
Leave a Reply