Using irb - Computer Science Programming Basics in Ruby (2013)

Computer Science Programming Basics in Ruby (2013)

Appendix D. Using irb

Oftentimes while programming, you will wonder about the syntax of a command or how something works in Ruby. Creating a new file and running it is the wrong option in many cases because it wastes a lot of time.

irb is Ruby’s interactive interpreter (short for Interactive Ruby). This is a great tool that you will want to learn to use, as it will greatly speed up time spent debugging code. We also use it throughout the book to give examples.

To run irb, first open a terminal.

In Windows, you can do this by opening the Start menu and clicking on Run. A small window will appear with a text box. Type cmd and hit Return. A black-and-white window that has a blinking cursor will open. Welcome to the terminal.

On a Mac, the Terminal is located in Applications→Utilities.

Type irb in the terminal to launch irb. When it launches, you will be greeted with a prompt to enter your first line of code:


To exit, either type exit or hit Ctrl-D. This is a terminating condition that allows you to exit most programs.