Hi,
Does the Ruby ‘==’ operator compares the ‘object_ids’ of the element
before
descending into comparing the elements?
I know about the equal? method, but I want something like following to
be
compared, and am worried about efficiency.
[x y z] and [x y z]
the arrays may be different objects, but the elements will be the same
object.
Thanks.
Surendra S.
http://ssinghi.kreeti.com, http://www.kreeti.com
Read my blog at: http://cuttingtheredtape.blogspot.com/
,----
| Great wits are sure to madness near allied,
| And thin partitions do their bounds divide.
|
| (John Dryden, Absalom and Achitophel, 1681)
`----
On 06-08-26, at 03:33, Surendra S. wrote:
Hi,
Does the Ruby ‘==’ operator compares the ‘object_ids’ of the
element before
descending into comparing the elements?
Depends on how the object receiving it implements it.
Jeremy T. [email protected] writes:
On 06-08-26, at 03:33, Surendra S. wrote:
Hi,
Does the Ruby ‘==’ operator compares the ‘object_ids’ of the
element before
descending into comparing the elements?
Depends on how the object receiving it implements it.
And how does hashes, and arrays implement it?
Thanks,
Surendra S.
http://ssinghi.kreeti.com, http://www.kreeti.com
Read my blog at: http://cuttingtheredtape.blogspot.com/
,----
| “O thou my friend! The prosperity of Crime is like unto the lightning,
| whose traitorous brilliancies embellish the atmosphere but for an
| instant, in order to hurl into death’s very depths the luckless one
| they have dazzled.” – Marquis de Sade
`----
On 8/26/06, Jeremy T. [email protected] wrote:
On 06-08-26, at 03:33, Surendra S. wrote:
Does the Ruby ‘==’ operator compares the ‘object_ids’ of the
element before
Depends on how the object receiving it implements it.
More exactly == is a method →
class Foo
def==(other)
self.class == other.class
end
end
f = Foo.new
g = Foo.new
f == 7 => false
f == f => true
f == g => true
pth