assoc

assoc

ri

 ------------------------------------------------------------ Array#assoc
      array.assoc(obj)   ->  an_array  or  nil
 ------------------------------------------------------------------------
      Searches through an array whose elements are also arrays comparing
      _obj_ with the first element of each contained array using obj.==.
      Returns the first contained array that matches (that is, the first
      associated array), or  nil  if no match is found. See also
       Array#rassoc .
 
         s1 = [ "colors", "red", "blue", "green" ]
         s2 = [ "letters", "a", "b", "c" ]
         s3 = "foo"
         a  = [ s1, s2, s3 ]
         a.assoc("letters")  #=> [ "letters", "a", "b", "c" ]
         a.assoc("foo")      #=> nil
 

refe

 Array#assoc
 --- assoc(key)
 
     配列配列を検索して、その 0 番目の要素が key に等しい最初の
     要素を返します。比較は == 演算子を使って行われます。
     該当する要素がなければ nil を返します。
 
     例:
         ary = 1,15], [2,25], [3,35?
         p ary.assoc(2)           # => [2, 25]
         p ary.assoc(100)         # => nil
         p ary.assoc(15)          # => nil
 
     Array#rassoc [Array/rassoc] も参照してください。