DEV Community

Cover image for 49 Days of Ruby: Day 3 - Interactive Ruby
Ben Greenberg
Ben Greenberg

Posted on

49 Days of Ruby: Day 3 - Interactive Ruby

Welcome to day 3 of the 49 Days of Ruby! 🎉

Today we are going to introduce ourselves to IRB (Interactive Ruby).

IRB is an integral tool when working with Ruby. It allows you to run Ruby expressions in a real-time environment. The tool will become an indispensable utility in your toolkit as you continue to figure out the contours of the language.

Lucky for us, when you installed Ruby yesterday you also installed IRB with it!

To start IRB run irb from the command line. Once you do so you will see something like this:

irb(main):001:0>
Enter fullscreen mode Exit fullscreen mode

You are now inside IRB.

We are introducing IRB first after installing Ruby. We have not yet learned about variables, conditions, or any other Ruby syntax. That's okay! We are showing IRB first, because so much of what comes after will depend on some comfort with it.

Run the following inside IRB: puts 'Hello World!'.

You will see the following output:

Hello World!
 => nil
Enter fullscreen mode Exit fullscreen mode

You just ran your first Ruby expression, congrats! The puts method outputs to the screen what you tell it to output. In this case, we outputted Hello World!.

Why did you see => nil on the line after the text output?

That's because Ruby will always return the last value in the expression. The method puts returns nil, so that is what you see at the conclusion.

(The nil itself comes from a special class in Ruby called NilClass. What's a class and what's NilClass? We'll get to that later on!)

To exit IRB, you can type exit and it will return you back to the command line.

That's it for today! Come back tomorrow for more Ruby goodness!

Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag #49daysofruby.

Top comments (0)