[#1551] Hashes as keys — "Nathaniel Talbott" <nathaniel@...>

I was just playing around with Hash#hash and discovered that you can't use a

13 messages 2003/09/23

Re: ostruct.rb patch

From: "Nathaniel Talbott" <nathaniel@...>
Date: 2003-09-24 02:06:42 UTC
List: ruby-core #1558
NAKAMURA, Hiroshi [mailto:nahi@keynauts.com] wrote:

> You define == and hash, not eql? and hash, right?
> What is the purpose of redefining #hash?

Oops! I forgot that #eql?, not #==, is the #hash counterpart (there's
entirely too much Java in my past). I'll drop the redefinition of #hash.


> BTW,
> 
> > +  def ==(other)
> > +    return false unless(other.kind_of?(OpenStruct))
> > +    return @table == other.instance_eval{@table}
> > +  end
> 
> You can use protected method to avoid this kind of 
> instance_eval. Ignore me if it's intentional.

I hadn't thought of that. Do you think a protected method is better? I'm
assuming it's probably faster.


Nathaniel

<:((><


In This Thread