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

Get Ruby Pocket Reference 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.