Getting Started With IRB

IRB stands for “Interactive Ruby”, and it’s a tool you should use to explore the power of Ruby.

Open up a terminal session in your IDE, type irb into the terminal, and hit enter. You should see that the next line of the terminal session will look slightly different than the others.

You can type in a Ruby expression into the IRB session and hit enter to execute that line of code. Not sure if you’ve got the right syntax for the script you’re working on? Open up an IRB and try it out.

$ irb
irb(main):001:0 > x = 1 + 2
 => 3
irb(main):002:1 > puts x
3
 => nil
irb(main):003:2 >

To exit out of the IRB session type the expression exit and hit enter.

You might be wondering why you keep seeing this after each expression is executed => something. That’s the “return” value of the statement. Ruby will always return a value from an expression. Keep this in mind as we move into methods.

IRB is a very useful tool so keep it handy!