How to Run Ruby Code

For running Ruby on your laptop, you first need to check whether ruby is installed or not. So open up Command Line or Terminal and type in ruby –version if this returns something like ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]. Then you have ruby installed on your system. Then your good to go and run Ruby on your computer otherwise you first need to install it on your system. Ruby can be downloaded from here – Download Ruby Programming Language.

Ruby can be simply run on a computer using ruby [options] [–] [program filename] [agruments] command, do note that in this command each one of component which is inside square brackets is optional so you may or may not use these.

Let’s see what options can be used in this command for running Ruby.

Option for Ruby Running CommandDescription
-0Secify a record separator
-aAutosplit mode with -n or -p
-cCheck Syntax only
-dSet debugging flags
-e ‘command’Execute one line of script
-F patternsplit() pattern with autosplit
-i [extension]Edit ARGV files in place
-IdirectorySpecify $LOAD_PATH directory
-KkcodeSpecify chracter set
-lEnable line-ending processing
-nAssume while gets();……. end loop around script
-pAssume loop like -n but print line also like sed

I hope that this article helps you to understand how to run ruby. If in case, you have some query and want to ask me then do comment below.

Comments to: How to Run Ruby Code

Your email address will not be published.