From: Ryan Davis Date: 2010-01-07T07:07:02+09:00 Subject: Re: what's String.hash On Jan 5, 2010, at 18:56 , Ruby Newbee wrote: > irb(main):038:0* x="hello" > => "hello" > irb(main):039:0> x.object_id > => 69352346 > irb(main):040:0> x.hash > => 267522041 > irb(main):041:0> y="hello".intern > => :hello > irb(main):042:0> y.object_id > => 246184 > irb(main):043:0> y.hash > => 246184 > > > What's the meanings of String.hash method? > does it have any relation to object_id? Thanks. You should be using ri to answer these questions: 501 % ri String.hash ------------------------------------------------------------ String#hash str.hash => fixnum From Ruby 1.8 ------------------------------------------------------------------------ Return a hash based on the string's length and content. 502 % ri Object.hash ------------------------------------------------------------ Object#hash obj.hash => fixnum From Ruby 1.8 ------------------------------------------------------------------------ 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. 503 % ri Object.object_id ------------------------------------------------------- Object#object_id obj.__id__ => fixnum obj.object_id => fixnum From Ruby 1.8 ------------------------------------------------------------------------ Returns an integer identifier for _obj_. The same number will be returned on all calls to +id+ for a given object, and no two active objects will share an id. +Object#object_id+ is a different concept from the +:name+ notation, which returns the symbol id of +name+. Replaces the deprecated +Object#id+.