--000e0cd115e6e018fc047e5a39d1
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Jan 29, 2010 at 7:36 PM, Angel Marques <angel21ccs / hotmail.com>wrote:

> Hi...I type
>
> h   "a" 100, "b" 200 }
> or
> d   :c 100, :f 200 }
>
> d.key(200)
>
> and the console show me the next error:
>  undefined method `key' for {"a"00, "b"00}:Hash (NoMethodError)
>
> what happens with this method, it's wrong?
> thanks
> --
> Posted via http://www.ruby-forum.com/.
>
>
Here are the hash methods: http://ruby-doc.org/core/classes/Hash.html
Notice that "key" is not listed.
If you look at the methods listed, you will see one called "index" and when
reading it's description, you see:

Returns the key for a given value. If not found, returns nil.
   h   "a" 100, "b" 200 }
   h.index(200)   #"b"
   h.index(999)   #nil


Which looks exactly like what you were trying to do.

Generally, you can find your way here from http://ruby-doc.org/ in the
orange section, select which version of Ruby you have, in the middle frame
along the top, select the Hash class, and it will display in the frame at
the bottom. You can also usually just google "ruby hash" and jump right to
the 1.8.6 docs.

--000e0cd115e6e018fc047e5a39d1--