[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

A tip about using Hash - and a documentation request

Per Velschow

1/22/2007 5:17:00 AM

I just spent several hours of investigating a problem that I had when
using instances of my own class as keys in a Hash. If you, like me, have
experience with this from a language like Java, you know that you have
to override both the hash method and the equality operator/method. What
took me by surprise was that Hash does NOT use the == operator when
comparing keys. Instead, it uses the eql? method. Thus, it is the eql?
method you have to define for your classes.

The above is actually documented in the Ruby core docs - but not in the
most obvious place in my opinion. It is mentioned only in the
Object.hash documentation. I never considered looking there for the
answer - I only looked at the docs for Hash and it makes no mention of
this fact. This may be my fault. But in my opinion this behavior is a
feature of the Hash class first and foremost. As such it is rather
important to document it in the Hash class.

/Per

P.S. One reason it took me so long to figure out is that Googling for
words like "hash", "key", etc. is not very specific and gives way too
many unrelated results. :)

--
Posted via http://www.ruby-....

6 Answers

Eric Hodel

1/22/2007 7:44:00 AM

0

On Jan 21, 2007, at 21:16, Per Velschow wrote:

> The above is actually documented in the Ruby core docs - but not in
> the
> most obvious place in my opinion. It is mentioned only in the
> Object.hash documentation. I never considered looking there for the
> answer - I only looked at the docs for Hash and it makes no mention of
> this fact. This may be my fault. But in my opinion this behavior is a
> feature of the Hash class first and foremost. As such it is rather
> important to document it in the Hash class.

Please provide a patch to the ruby-doc mailing list, or to ruby-core
and I'll commit it. You'll find the RDoc for Hash in hash.c in a
ruby tarball (or SVN), right above Init_Hash. It'll be easiest to
apply from trunk or ruby_1_8.

ruby-doc@ruby-lang.org

ruby-core@ruby-lang.org

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Per Velschow

1/22/2007 9:49:00 AM

0

I've never made a patch before, so I decided to follow the instructions
given at http://www.ruby-lang.org/en/community/... (up until
point 3). So I have a patch file now and I have run make and make test
with success. I had little success trying to install the docs using make
install-doc though. It creates yaml files only that I don't know what to
do with.

So how do you want me to proceed? I have the patch file. I could login
and submit it to the tracker as explained in the instructions from
above. Or do you want me to sign up to one of the mailing lists you
mentioned and post it there?

--
Posted via http://www.ruby-....

Eric Hodel

1/22/2007 10:09:00 AM

0

On Jan 22, 2007, at 01:49, Per Velschow wrote:

> I've never made a patch before, so I decided to follow the
> instructions
> given at http://www.ruby-lang.org/en/community/... (up until
> point 3). So I have a patch file now and I have run make and make test
> with success. I had little success trying to install the docs using
> make
> install-doc though. It creates yaml files only that I don't know
> what to
> do with.

After installing the documentation you should be able to

ri Hash

and see your new documentation.

You should also be able to run:

rdoc --op rdoc hash.c

then open rdoc/index.html in your browser to find your RDoc.

> So how do you want me to proceed? I have the patch file. I could login
> and submit it to the tracker as explained in the instructions from
> above. Or do you want me to sign up to one of the mailing lists you
> mentioned and post it there?

Tracker works great too. Assign it to me, if the tracker allows you
to. It may be a while before I get around to committing it.

Thanks!

--
Eric Hodel - drbrain@segment7.net - http://blog.se...

I LIT YOUR GEM ON FIRE!


Ryan Davis

1/22/2007 10:12:00 AM

0


On Jan 22, 2007, at 1:49 AM, Per Velschow wrote:

> I've never made a patch before, so I decided to follow the
> instructions
> given at http://www.ruby-lang.org/en/community/... (up until
> point 3). So I have a patch file now and I have run make and make test
> with success. I had little success trying to install the docs using
> make
> install-doc though. It creates yaml files only that I don't know
> what to
> do with.

For the record... You RULE.


Per Velschow

1/22/2007 11:48:00 AM

0

OK, I submitted it to the tracker. It was not possible for me to assign
it. I made a note of it in the description instead.

--
Posted via http://www.ruby-....

The Peeler

12/7/2012 6:16:00 PM

0

On Fri, 7 Dec 2012 11:40:08 -0500, "All Bark and No Bite", aka Walt
Humpton, aka Caroloony Reb, the subnormal moron and attested schizo from
the States, wrote:


>
>>http://wakeupfromyourslumber.com/blog/fester/manifesto-first-anti-jewish-congress-dresden-se...
>
> Kewel!

Oh, listen, "All Bark and No Bite" is yapping!!! LOL

--
Bert to our resident schizo:
"The voices in your head are not a reliable source of information."
MID: <XnsA0E69C0A32C1DVeebleFetzer@216.250.188.141>