[#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: "NAKAMURA, Hiroshi" <nahi@...>
Date: 2003-09-24 02:00:45 UTC
List: ruby-core #1557
Hi, Nathaniel,

> From: "Nathaniel Talbott" <nathaniel@talbott.ws>
> Sent: Wednesday, September 24, 2003 10:39 AM

> I've been finding OpenStruct to be very useful lately, and then I discovered
> (while testing something) that they can't be effectively compared. I've
> included a patch, with a test, to add that functionality. I'm not 100% sure
> about the #hash method; this patch was what precipated my earlier question
> about the Hash#hash method. Comments are welcome.

You define == and hash, not eql? and hash, right?
What is the purpose of redefining #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.

Regards,
// NaHi

In This Thread