Section 2. Objects, Classes, and Modules

Like many modern programming languages, Ruby is object oriented. However, Ruby could be considered to be a purer object-oriented language than many. To see what I mean, let’s look closer at that expression 30.minutes.ago from the previous example. You might have naturally assumed that it is a bit of syntactic sugar, something that the Ruby interpreter intercepts and translates into something real like Time.now - 30*60 upon execution. Indeed, that is how it would have to work in languages such as C++, Java, and PHP, where integers, floats, and sometimes strings are treated as primitives below the OOP framework. In Ruby, however, everything is an object—even integers—as the following example demonstrates. ...

Get Rubyisms in Rails 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.