Ron Green wrote: > Peter Cooper wrote: >> On 9/9/07, Ron Green <rongreen1 / mac.com> wrote: >>> Marcel Molina Jr. wrote: >>>> It should be noted though that String#hash isn't garaunteed to be >>>> unique. >>> Then,again I ask, what is it good for? >> >> It's still useful as a hash. Marcel wasn't wrong, but *no* fixed size >> hash >> is "guaranteed" to be unique as that's absolutely impossible, per the >> pigeonhole principle >> (http://en.wikipedia.org/wiki/Pigeonhole_principle). >> String#hash's hash is of a far lower "quality" than that offered by, >> say, >> SHA-1 or SHA-2. >> >> Regards, >> Peter Cooper >> http://www.rubyinside.com/ > > Peter, > If Its not guaranteed to be unique, then it can't be used for identity. > Can you give me an example of how i would use string.hash? In general, you wouldn't use String#hash, although you might conceivably want to override it. It's there for Hash. From the documentation on Object#hash: "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." Note the direction of implication: a == b => a.hash == b.hash, not a.hash == b.hash => a == b. -- Alex