File
The File class in Ruby does two things. First, it’s a subclass of IO, meaning it handles reading data from and writing data to files. Second, it adds a number of methods for manipulating files as objects, similar to the Dir class. Since the reading and writing behavior is mostly managed by methods defined in IO, we’ll discuss it when we look at IO in IO. Here, we’ll look at file-specific manipulations.
Most File manipulation methods are class methods, while most of the read/write methods are instance methods.
Opening a File
You create a File instance with File.new(filename, mode = "r", permissions = 0666, *options) or File.open(filename, mode = "r", permissions = 0666, *options) [{block}]. (Note that this doesn’t necessarily create the ...
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.
Read now
Unlock full access