A Change in Convention

Up to this point, most examples you've seen have been either scripts or parts of irb sessions. irb is a nice learning tool, because it lets you see the effects of a line of code immediately. Scripts are the form of the actual work you will do in Ruby, and they let you control exactly what information appears in the output.

From this point forward, to save space and clutter most of our code examples will appear naked, meaning that you can either type them into irb or run them in script form. Let's illustrate with a short piece of code, then walk through an equivalent irb session.

ltrs = ("r" .. "u").to_a  #–> ["r", "s", "t", "u"]
ltrs[1].capitalize!       #  ltrs == ["r", "S", "t", "u"]
puts ltrs.length          #  4

Comments have been ...

Get Sams Teach Yourself Ruby in 21 Days 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.