Ruby == how does it works?

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 Singhi
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)

`----

Depends on how the object receiving it implements it.

···

On 06-08-26, at 03:33, Surendra Singhi wrote:

Hi,
  Does the Ruby '==' operator compares the 'object_ids' of the element before
descending into comparing the elements?

--
Jeremy Tregunna
jtregunna@blurgle.ca

Jeremy Tregunna <jtregunna@blurgle.ca> writes:

···

On 06-08-26, at 03:33, Surendra Singhi 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 Singhi
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

`----

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

···

On 8/26/06, Jeremy Tregunna <jtregunna@blurgle.ca> wrote:

On 06-08-26, at 03:33, Surendra Singhi wrote:
> Does the Ruby '==' operator compares the 'object_ids' of the
> element before

Depends on how the object receiving it implements it.

ri Hash#==
---------------------------------------------------------------- Hash#==
     hsh == other_hash => true or false

···

On 8/26/06, Surendra Singhi <efuzzyone@netscape.net> wrote:

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

------------------------------------------------------------------------
     Equality---Two hashes are equal if they each contain the same
     number of keys and if each key-value pair is equal to (according to
     +Object#==+) the corresponding elements in the other hash.

        h1 = { "a" => 1, "c" => 2 }
        h2 = { 7 => 35, "c" => 2, "a" => 1 }
        h3 = { "a" => 1, "c" => 2, 7 => 35 }
        h4 = { "a" => 1, "d" => 2, "f" => 35 }
        h1 == h2 #=> false
        h2 == h3 #=> true
        h3 == h4 #=> false

ri Arrray#==
--------------------------------------------------------------- Array#==
     array == other_array -> bool
------------------------------------------------------------------------
     Equality---Two arrays are equal if they contain the same number of
     elements and if each element is equal to (according to Object.==)
     the corresponding element in the other array.

        [ "a", "c" ] == [ "a", "c", 7 ] #=> false
        [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true
        [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false