Category: Ruby Example

  • Creating Self-Contained Ruby

    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…

  • Executing Ruby File from Terminal

    We will be creating a ruby file in VSCode with the name ‘SimpleExample.rb’. SimpleExample.rb: You can also try this code with Online Ruby Compiler Run Code We will now execute the ruby file from the terminal using the command “ruby <filename>”.

  • Interactive Execution of Ruby

    Ruby is an interpreted programming language. This basically means that Ruby source code is not pre-compiled like it is with languages like C or C++, but rather is compiled and executed at run time. One advantage of being an interpreted language is that we can type Ruby code directly into the interpreter and have it…

  • Executing Ruby from the Command Line

    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: You can also try this code with Online Ruby Compiler Run Code Output: Though this ‘-e’ flag only allows a single line of…

  • Basic Ruby Example

    Ruby is not only a flexible scripting language in terms of syntax, but it is also extremely flexible in terms of how scripts can be executed. In this section, we’ll look at some simple Ruby examples to learn Ruby before diving into the various ways Ruby code can be executed. The most basic example we…