Slevin McGuigan
2010-12-05 21:29:34 UTC
Hi *,
I am new to ruby and new to this mailinglist. I hope my question isn't too
simple to be coped with. But as I want to get involved in the ruby community
I choosed this one as a lightweight issue to start with.
I stumbled about the behaviour of Hash#key (which is a strange method
anyway, imho. I guess I won't ever use it). The behavior of #key isn't
obvious in case there is more then one occurance of the key
testhash = {
'1' => 'a',
'2' => 'b',
'3' => 'a'
}
puts "#{testhash.key('a')}" # => 1
testhash.delete('1')
puts "#{testhash.key('a')}" # => 3
http://rdoc.info/docs/ruby-core/1.9.2/Hash sais that "Hashes enumerate their
values in the order that the corresponding keys were inserted" Hence the
behavior is following the documentation (or vice versa)
But both http://rdoc.info/docs/ruby-core/1.9.2/Hash#key-instance_method and
http://www.ruby-doc.org/ruby-1.9/classes/Hash.html#M000387 only say "Returns
the key for a given value. If not found, returns nil".
And question #1 is: What is the best place too look/the official
documentation? And is this mailing list the proper way to discuss
documentation flaws?
And question #1 is: Shouldn't there be something in the documentation of
hash#key like "... If there is more then one occurance of the key the first
value is returned"
Best Regards,
Slevin
--
My system: Ubuntu 9.10, ruby 1.9.1
***@egon:/home/egon> uname -a
Linux egon 2.6.31-22-generic #68-Ubuntu SMP Tue Oct 26 16:38:35 UTC 2010
i686 GNU/Linux
***@egon:/home/egon> cat /etc/lsb\-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"
***@egon:/home/egon> ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i486-linux]
I am new to ruby and new to this mailinglist. I hope my question isn't too
simple to be coped with. But as I want to get involved in the ruby community
I choosed this one as a lightweight issue to start with.
I stumbled about the behaviour of Hash#key (which is a strange method
anyway, imho. I guess I won't ever use it). The behavior of #key isn't
obvious in case there is more then one occurance of the key
testhash = {
'1' => 'a',
'2' => 'b',
'3' => 'a'
}
puts "#{testhash.key('a')}" # => 1
testhash.delete('1')
puts "#{testhash.key('a')}" # => 3
http://rdoc.info/docs/ruby-core/1.9.2/Hash sais that "Hashes enumerate their
values in the order that the corresponding keys were inserted" Hence the
behavior is following the documentation (or vice versa)
But both http://rdoc.info/docs/ruby-core/1.9.2/Hash#key-instance_method and
http://www.ruby-doc.org/ruby-1.9/classes/Hash.html#M000387 only say "Returns
the key for a given value. If not found, returns nil".
And question #1 is: What is the best place too look/the official
documentation? And is this mailing list the proper way to discuss
documentation flaws?
And question #1 is: Shouldn't there be something in the documentation of
hash#key like "... If there is more then one occurance of the key the first
value is returned"
Best Regards,
Slevin
--
My system: Ubuntu 9.10, ruby 1.9.1
***@egon:/home/egon> uname -a
Linux egon 2.6.31-22-generic #68-Ubuntu SMP Tue Oct 26 16:38:35 UTC 2010
i686 GNU/Linux
***@egon:/home/egon> cat /etc/lsb\-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"
***@egon:/home/egon> ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i486-linux]