Find a key-value pair : find « Hash « Ruby






Find a key-value pair


squares = {0=>0, 1=>1, 2=>4, 3=>9}
p squares.find { |key, value| key > 1 }          # => [2, 4]

 

Related examples in the same category