21.3. Using irb
The irb utility (interactive Ruby) has been distributed with Ruby for many years. It can be thought of as a “testbed” or “playground” where you try out quick hacks and new ideas.
Basic usage of irb is simple. When you start it, you get a prompt where you can type Ruby expressions; each expression is evaluated, and the result is printed for you. Here’s a small example of a session:
$ irb irb(main):001:0> "cell" + "o" => "cello" irb(main):002:0> 3*79 => 237 irb(main):003:0> Dir.entries(".").size => 17 irb(main):004:0> rand => 0.850757389880155 irb(main):005:0> rand => 0.679879756672551 irb(main):006:0> defined? foo => nil irb(main):007:0> defined? Object => "constant" irb(main):008:0> quit $
Of course, it’s more than just a calculator. ...
Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition 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.