January 2024
Intermediate to advanced
718 pages
20h 15m
English
Ruby provides what looks at first sight like two separate sets of input and output (I/O) routines. The first is the simple interface we’ve been using a lot so far:
| | print "Enter your name: " |
| | name = gets |
This whole set of I/O-related methods is implemented in the Kernel module, including gets, open, print, printf, putc, puts, readline, readlines, and test. The I/O methods are available to all objects, and they make it simple and convenient to write straightforward Ruby programs. These methods typically do I/O to standard input and standard output, which makes them useful for writing simple tasks.
The other way to do I/O, which gives you more control, is to use Ruby’s dedicated IO classes.
Read now
Unlock full access