Chapter 12New Classes of Objects

So far we’ve seen several kinds, or classes, of objects: strings, integers, floats, arrays, a few special objects (true, false, and nil), and so on. In Ruby, these class names are always capitalized: String, Integer, Float, Array, File, and Dir. (You remember back here when we asked the File class to open a file for us, and it handed us back an actual file, which we called, in a fit of rabid creativity, f? Those were the days…. Anyway, we never ended up needing an actual directory object from Dir, but we could have gotten one if we had asked nicely.)

File.open was a mildly unusual way to get an object from a class. In general, you’ll use the new method:

alpha = Array.new + [12345] ​# Array addition.
beta = ...

Get Learn to Program, 2nd Edition 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.