Using Ruby Interactively

If you run ruby without providing a command or a program file name, something funny happens. No prompt appears on the screen, but the computer just sits there waiting for you to type things. (You may have already stumbled into this situation.) What's going on? You have invoked the ruby interpreter, and what the interpreter wants to do is to run a Ruby script; that is its only reason for living. Since you didn't provide a script in advance, the interpreter sits patiently, waiting for you to fulfill your obligation and give it something to do.

You can type an instruction or two, or a lengthy script if you want, pressing Enter at the end of each line; when you finish, it will execute the script and return you to your normal ...

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.