assoc

hash.assoc(obj) â an_array or nil
Instance Public methods

Searches through the hash comparing obj with the key using ==. Returns the key-value pair (two elements array) or nil if no match is found. See Array#assoc.

1
2
3
4
h = {"colors"  => ["red", "blue", "green"],
     "letters" => ["a", "b", "c" ]}
h.assoc("letters"#=> ["letters", ["a", "b", "c"]]
h.assoc("foo")      #=> nil
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.