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.

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!"

Note

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.