Skip to Main Content
Learn to Program, 2nd Edition
book

Learn to Program, 2nd Edition

by Chris Pine
March 2009
Intermediate to advanced content levelIntermediate to advanced
194 pages
4h
English
Pragmatic Bookshelf
Content preview from Learn to Program, 2nd Edition

The gets Method

If puts means put string, I’m sure you can guess what gets stands for. And just as puts always spits out strings, gets retrieves only strings. And whence does it get them?

From you! Well, from your keyboard, anyway. And since your keyboard makes only strings, that works out beautifully. What actually happens is that gets just sits there, reading what you type until you press Enter. Let’s try it:

puts gets
=> Is there an echo in here?
<= Is there an echo in here?

Of course, whatever you type will just get repeated back to you. Run it a few times, and try typing different things.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn to Program, 3rd Edition

Learn to Program, 3rd Edition

Chris Pine
The Book of Ruby

The Book of Ruby

Huw Collingbourne

Publisher Resources

ISBN: 9781680500172Errata