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

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 = ...
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