O'Reilly logo

Ruby Phrasebook by Jason Clinton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Working with Files

In many ways, this chapter is closely related to the previous chapter, “Working with Pipes”. The principals are the same because both are implemented as children of the IO class.

Indeed, in Unix, the distinction between IO devices and “files” is significantly blurred. For instance, /dev/random is a “file” in the sense that it has a name and path. But it’s also a direct way to “read” the random numbers generator in to any program that accepts files as input.

In Ruby, all IO objects have basic input and output support, depending on which file mode the object was opened with.

Opening and Closing Files

Certainly, one of the tried-and-true conventions in Ruby is using code blocks to ensure that resources are automatically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required