From: Darshan Ishaya Date: 2006-11-25T01:30:59+09:00 Subject: Re: Problems with String#hash darshan@shadow ~ $ ri -T Object#hash ------------------------------------------------------------ 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. darshan@shadow ~ $ ri -T "String#hash" ------------------------------------------------------------ String#hash str.hash => fixnum ------------------------------------------------------------------------ Return a hash based on the string's length and content. I don't see any reason you should assume the hash to be the same on different machines, or even across different instances of ruby. I'd only assume the hashes of eql? objects to be equal if they are computed within the same run of the script. Your nasty problem seems to be that you were making an assumption not guaranteed to be true. What are you actually trying to accomplish? Maybe we can help you find another way. Darshan BTW I get the same negative value as you do in your last (4th!) example. Could be a 64-bit thing. George Moschovitis wrote: > Dear devs, > > I am facing a very NASTY problem with String#hash > > Here is the same code that I run on 3 different computers: > > root@kosh:~ # irb > irb(main):001:0> "User".hash > => 690465448 > irb(main):002:0> VERSION > => "1.8.2" > > C:\Documents and Settings\drak>irb > irb(main):001:0> "User".hash > => 690465448 > irb(main):002:0> VERSION > => "1.8.4" > > http://tryruby.hobix.com/ > Interactive ruby ready. >>> "User".hash > => 690465448 >>> VERSION > => "1.8" > > root@victory:~# irb > irb(main):001:0> "User".hash > => -1457018200 > irb(main):002:0> VERSION > => "1.8.4" > > Please nottice that on the last case I get a different result! Any > idea why this happens? > > thanks in advance for any help! > > George. > >