Ruby Monstas


IRB (Interactive Ruby)

IRB

IRB stands for Interactive Ruby

Command line program for playing around with Ruby

Part of any Ruby installation

Starting IRB

  1. Open your command line (Terminal, Powershell or similar)
  2. Type in the window:
    irb
  3. Push the Enter key

Your command line will now look like this:

irb(main):001:0>

Running Ruby code in IRB

  1. Type some Ruby code, for example:
    puts "Hello World!"
  2. Push the Enter key

Your command line will now look like this:

irb(main):001:0> puts "Hello World!"
Hello World!
=> nil
irb(main):002:0>

Running Ruby code in IRB

What has happened here?

  1. IRB checks that it's proper Ruby code (syntax check)
  2. IRB executes the command:
    Hello World!
    output
  3. IRB shows the return value of the command:
    => nil

IRB history

You can access the history of previous commands you entered with

Go back and forth with and

Try it now!

Exiting IRB

  • Type:
    exit
    and Enter
  • Type:
    quit
    and Enter
  • Use the shortcut: Ctrl + D

You are now back in your normal command line

Important: When you exit IRB, your code is gone! It's not saved anywhere!

IRB

Today, we will only use IRB

Next time, we will learn about using the text editor to write larger programs

Additional Resources

Ruby For Beginners: Interactive Ruby

What questions do you have?