Interactive Ruby (irb)

Learn to Program, Third Edition — by Chris Pine (91 / 116)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 15 Beyond This Book | TOC | The PickAxe: Programming Ruby 👉

If you installed Ruby, then you installed irb. To use it, go to your command prompt and type irb. When you’re in irb, you can type in any Ruby expression you want, and it’ll tell you the value of that expression. Type in 1+2, and it’ll tell you 3 (note that you don’t have to use puts). It’s kind of like a giant Ruby calculator. When you’re done, type exit.

I use irb when I have something I want to test real quick. For example, is it array.len or array.length? (I program in several languages, so it’s easy to get confused.) Or maybe I want to know if arrays have a reverse method like strings do? I can test these in a few seconds with irb. You can even define methods and classes in irb (though they’ll only last until you exit irb).

There’s a lot more to irb than this, but you can learn all about it in the PickAxe.

👈 Chapter 15 Beyond This Book | TOC | The PickAxe: Programming Ruby 👉

Learn to Program, Third Edition by Chris Pine can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.