ruby - Select a value from an array of hashes -
from array of hashes:
response = [ {"label"=>"cat", "name"=>"kitty", "id"=>189955}, {"label" => "dog", "name"=>"rex", "id" => 550081} ]
is there way write like:
response.name.kitty
to retrieve hash contains value:
{"label"=>"cat", "name"=>"kitty", "id"=>189955}
you can -
response.select{|x| x["name"] == "kitty"}.first
Comments
Post a Comment