Using irb

Now that you’ve started it, irb is waiting for you to type your first line. Lines consist of one or more expressions.


As far as Ruby is concerned, an expression is just a bit of code that has a value. In fine computer programming tradition, let’s see how irb reacts to the expression “Hello, world!”

irb(main):001:0> "Hello, world!"
=> "Hello, world!"


This listing shows the line you need to type as well as how irb responds. Note also that irb shows you line numbers at the beginning of each line. I will occasionally refer to these numbers, as well.

What has happened here? You typed “Hello, world!”, and irb happily spat it right back at you. The interesting part of this is what isn’t explicit. The expression you entered has a ...

Get Ruby by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.