From: Robert Klemme Date: 2012-12-10T02:38:59+09:00 Subject: Re: Searching a hash by value On Sun, Dec 9, 2012 at 2:21 PM, Ferdous ara wrote: > may be i need to design my logic in a different way > let me explain > > basically in that hash table (out put of JSON) > > as key => value > > > > i got like this > [ > { > "notes_expanded" : "check_maintanance_mode", > "host_comments" : [], > "host_icon_image_expanded" : "", > "checks_enabled" : 1, > "max_check_attempts" : 3, > "host" : service2.home.lan, > > } > { > "notes_expanded" : "check_memory ", > "host_comments" : [], > "host_icon_image_expanded" : "", > "checks_enabled" : 1, > "max_check_attempts" : 3, > "host" : service.home.lan, > > } > { > "notes_expanded" : "check_maintanance_mode", > "host_comments" : [], > "host_icon_image_expanded" : "", > "checks_enabled" : 1, > "max_check_attempts" : 3, > "host" : service.home.lan, > > } > ] > > So Basically i want to get all the host which > notes_expanded = check_maintanance_mode > so i should get only 2 > > Does it make sense ?? Yes, but it's something completely different than selecting from a Hash based on values. You rather want something like items = stuff.select {|h| h["notes_expanded"] == "check_maintanance_mode"} Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/