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,==
returnstrue
only ifobj
andother
are the same object. Typically, this method is overridden in descendant classes to provide class-specific meaning. Unlike==
, theequal?
method should never be overridden by subclasses: it is used to determine object identity (that is,a.equal?(b)
if and only ifa
is the same object asb
). Theeql?
method returnstrue
ifobj
andother
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
andString
) 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 toid
for a given object, and no two active objects will share anid
.Object#object_id
is a different concept from the:name
notation, which returns the symbolid
ofname
. Replaces the deprecatedObject#id
.obj
.class
Returns the class of
obj
, now preferred overObject#type
, because an object’s type in ...
Get Ruby Pocket Reference now with O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.