From: Brian Candler Date: 2011-05-28T04:57:31+09:00 Subject: Re: Hash .each and different action for each key Igor Nn wrote in post #1001604: > What I would like to do is loop through the hash and do a different > action based on each unique key. > > my_hash_table.each_pair do |k, v| > # Call a method if a hash key == "a" > # Call a different method if hash key == "b" > # Call a third method if a hash key == "c" > end > > I have been trying to implement this with "if" and "case", but the loop > stops once the first argument is satisfied. Then show your code. "if" and "case" will be able to do this just fine. Make a small *standalone* test program, e.g. start it with my_hash_table = {"a"=>42, "b"=>999, "c"=>123} Then when you post it here, we will be able to run it too and duplicate your problem. -- Posted via http://www.ruby-forum.com/.