O'Reilly logo

Ruby Pocket Reference by Michael Fitzgerald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Object Class

These public methods are in the Object class, the base class for Ruby. This documentation is adapted and abbreviated from http://www.ruby-doc.org/core/classes/Object.html, where you can find code examples and longer explanations. Object includes the Kernel module, whose methods are listed in the next section.

Object Instance Methods

obj == other [or] obj.equal?(other) [or] obj.eql?(other)

At the Object level, == returns true only if obj and other are the same object. Typically, this method is overridden in descendant classes to provide class-specific meaning. Unlike ==, the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) if and only if a is the same object as b). The eql? method returns true if obj and other have the same value.

obj === other

For class Object, effectively the same as calling ==, but typically overridden by descendants to provide meaningful semantics in case statements.

obj other

Overridden by descendants (notably Regexp and String) to provide meaningful pattern-match semantics.

obj._ _id_ _ [or] obj.object_id

Returns an integer identifier for obj. The same number will be returned on all calls to id for a given object, and no two active objects will share an id. Object#object_id is a different concept from the :name notation, which returns the symbol id of name. Replaces the deprecated Object#id.

obj.class

Returns the class of obj, now preferred over Object#type, because an object's type in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required