On 6/27/06, Eric Hodel <drbrain / segment7.net> wrote: > On Jun 26, 2006, at 5:06 PM, Alexandru Popescu wrote: > > > On 6/27/06, Eric Hodel <drbrain / segment7.net> wrote: > >> On Jun 26, 2006, at 4:38 AM, Alexandru Popescu wrote: > >> > >> > I have posted a quick (reminder like) entry about how equality is > >> > handled by Ruby and Java: > >> > > >> > http://themindstorms.blogspot.com/2006/06/parallel-of-equality- > >> in-2- > >> > worlds-ruby.html > >> > > >> > However, I feel I have missed to explain correctly why eql? and == > >> > are both needed. > >> > >> #eql? is used to resolve key collisions in hashes. > > ^^^ This line is the important one. I feel it describes adequately > what #eql? is needed for. > > >> If two objects have the same #hash and are #eql? then they refer to > >> the same hash key. If two objects have the same #hash and are not > >> #eql? they refer to different hash keys. > > > > ... and still wondering how is this answering my question (however > > thanks for the intention). > > #eql? is needed because #== doesn't do what #eql? does. > > Or where you looking for a different answer? > Quoting myself: The problem I was facing was to explain why == and eql? are both needed, and when their implementation may be different. The problem I see is not that #eql? is needed because #== doesn't do what #eql? does (because if you look logically at this sentence it doesn't make much sense: there is an infinitiy of methods xxx that should be needed because #== doesn't do what #xxx does :-) ). I see no good reasons, and I haven't found any good reference for cases where these methods are differently implemented. At this moment my interpretation is: #eql? is just syntactic sugar of #==, needed for objects used in hashes (because hashes use #eql? and not #==). ./alex -- .w( the_mindstorm )p. --- (http://themindstorms.blogspot.com)