Hi Brian,

On Thursday 05 May 2005 12:24, Brian Schr?der wrote:
>
> I think the difference is:
>
> irb(main):005:0> [1,2].hash === [1,2].hash
> => true
> irb(main):006:0> {1=>2}.hash === {1=>2}.hash
> => false
>

ri Object.hash says

------------------------------------------------------------ Object#hash
     obj.hash    => fixnum
------------------------------------------------------------------------
     Generates a +Fixnum+ hash value for this object. This function must
     have the property that +a.eql?(b)+ implies +a.hash == b.hash+. The
     hash value is used by class +Hash+. Any hash value that exceeds the
     capacity of a +Fixnum+ will be truncated before being used.

So if a.eql?(b), then a.hash MUST EQUAL b.hash.

Lets see:

 irb(main):038:0> a={1=>2}
 => {1=>2}
 irb(main):039:0> b={1=>2}
 => {1=>2}
 irb(main):040:0> a.eql?(b)
 => true
 irb(main):041:0> a.hash == b.hash
 => false

So what gives?

 irb(main):034:0> {1=>2}.hash => -605137920
 irb(main):035:0> {1=>2}.hash => -605147880
 irb(main):036:0> {1=>2}.hash => -604944118

Confused...

Andrew