--Le lundi 25 septembre 2006 20:29 +0300, "Sébastien Grosjean (ZenCocoon)" écrivait : > Salut, > > dans un "Hash" Je souhaite retrouver une clé en ne connaissant que la > valeur. Dans le cas suivant, comment récupérer "key_1" quand on ne > connait que "value_1" > > MY_HASH = [ > ["key_1", "value_1"], > ["key_2", "value_2"] > ]
Hello :) utilise la methode "index" : $ ri Hash.index ------------------------------------------------------------- Hash#index hsh.index(value) => key ------------------------------------------------------------------------ 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 -- Bruno Zuzzé (bozze) _______________________________________________ Railsfrance mailing list Railsfrance@rubyonrails.fr http://lists.rubyonrails.fr/mailman/listinfo/railsfrance