Ruby allows users to run lines of code as command-line options to the ruby tool. The ‘-e’ command line flag is used to accomplish this. Let’s run ‘Hello Ninjas! Let’s learn Ruby.’.
Example:
ruby -e ' print "Hello Ninjas! Let’s learn Ruby.\n" '
You can also try this code with Online Ruby Compiler
Run Code
Output:
Though this ‘-e’ flag only allows a single line of code to be executed, this does not necessarily prevent the use of multiple ‘-e’ flags on a single command line to execute multiple lines. We can use multiple ‘-e’ flags.
Example:
ruby -e ' print "Hello Ninjas! Let’s learn Ruby.\n" ' -e ' print "Using of extra -e flag allowed printing multiple lines.\n" ' -e ' print "Hope you learned something new today!\n" '
You can also try this code with Online Ruby Compiler
Run Code
Or
ruby -e ' print "Hello Ninjas! Let’s learn Ruby.\nUsing of extra -e flag allowed printing multiple lines.\nHope you learned something new today!\n" '
You can also try this code with Online Ruby Compiler
Run Code
Leave a Reply