Salut,
Frederick Ros wrote:
Jean-François wrote :
| >Y'a bien une solution mais pas très optimisé je trouve:
| >
| >def my_fonction(value)
| > for elements in MY_TABLE
| > (return elements[0]) if elements[1] == value
| > end
| > return nil
| >end
| >
| >Si vous avez mieux je suis une fois de plus preneur ;-)
|
| Une sous Rails avec group_by :
Et avec Array.rassoc ??
ri Array.rassoc
----------------------------------------------------------- Array#rassoc
array.rassoc(key) -> an_array or nil
------------------------------------------------------------------------
Searches through the array whose elements are also arrays.
Compares key with the second element of each contained array using
==. Returns the first contained array that matches. See also
Array#assoc.
a = [ [ 1, "one"], [2, "two"], [3, "three"], ["ii", "two"] ]
a.rassoc("two") #=> [2, "two"]
a.rassoc("four") #=> nil
Tous cela me parait très intérressant, merci Jean-François et Frederick
--
Sebastien Grosjean - ZenCocoon
_______________________________________________
Railsfrance mailing list
Railsfrance@rubyonrails.fr
http://lists.rubyonrails.fr/mailman/listinfo/railsfrance