The Second Object: other

Programming in Ruby wouldn't be very much fun if only the self object were available; it would be no more interesting than living in a world all alone. We would like to be able to populate our universe with more objects.

If we want another object that we can simply call “other,” we say

						other = Object.new
					

This is pretty close to how you would state the request out loud: “Let other be a new object.” But as it turns out, there is a good reason for the reversal of the last two words in the statement: new is a method name, a message which requests that a new object be created. What receives the message is not an object in the sense that we have so far understood, but a Class object. For now you don't have to worry about ...

Get Sams Teach Yourself Ruby in 21 Days 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.