Is there a Ruby equivalent for Python's "is"? It tests whether two objects are identical (i.e. have the same memory location).
From stackoverflow
cdleary
-
Use
a.equal? bhttp://www.ruby-doc.org/core/classes/Object.html
Unlike ==, the equal? method should never be overridden by subclasses: it is used to determine object identity (that is, a.equal?(b) iff a is the same object as b).
From John Millikin -
You could also use
__id__. This gives you the objects internal ID number, which is always unique. To check if to objects are the same, trya.__id__ = b.__id__This is how Ruby's standard library does it as far as I can tell (see
group_byand others).From wvdschel
0 comments:
Post a Comment