Ruby Programming/Notation conventions

← Ruby editors | Interactive Ruby →


Command-line examplesEdit

In this tutorial, examples that involve running programs on the command-line will use the dollar sign to denote the shell prompt. The part of the example that you type will appear bold. Since the dollar sign denotes your shell prompt, you should not type it in.

For example, to check what version of Ruby is on your system, run:

$ ruby -v

Again, do not type the dollar sign – you should only enter "ruby -v" (without the quotes). Windows users are probably more familiar seeing "C:\>" to denote the shell prompt (called the command prompt on Windows).

An example might also show the output of the program.

$ ruby -v
ruby 1.8.5 (2006-08-25) [i386-freebsd4.10]

In the above example, "ruby 1.8.5 (2006-08-25) [i386-freebsd4.10]" is printed out after you run "ruby -v". Your actual output when you run "ruby -v" will vary depending on the version of Ruby installed and what operating system you are using.

Running Ruby scriptsEdit

For simplicity, the following convention is used to show a Ruby script being run from the shell prompt.

$ hello-world.rb
Hello world

However, the actual syntax that you will use to run your Ruby scripts will vary depending on your operating system and how it is setup. Please read through the Executable Ruby scripts section of the Hello world page to determine the best way to run Ruby scripts on your system.

Running irbEdit

Ruby typically installs with "interactive ruby" (irb) installed along with it. This is a REPL that allows you to experiment with Ruby, for example:

$ irb
>> 3 + 4
=> 7
>> 'abc'
=> "abc"
Last modified on 18 June 2010, at 23:46