From: Pit Capitain Date: 2009-02-17T03:43:35+09:00 Subject: Re: How to do this complicated logic in ruby 2009/2/16 Valentino Lun : > I cannot figure out the logic to doing this in ruby (even in other > language). Can someone give me some hints on this? Thanks While I agree on what the others have said, that you should create a better data structure, here's a way to do what you wanted with your array of hashes. But look at the other posts. It's easy to build good data structures in Ruby. # create a key for the given record to be used in the pcat hash def pcat_key(record) [record["hosp"], record["loc"], record["psec"]] end # build hash with valid pcat values pcat = {} my_array.each do |record| next unless record["server"] == record["hosp"] pcat[pcat_key(record)] = record["pcat"] end # look for invalid records my_array.each do |record| next if record["pcat"] == pcat[pcat_key(record)] # do something with the invalid record p record end Regards, Pit