From: Anurag Priyam Date: 2011-05-28T16:21:10+09:00 Subject: Re: Hash .each and different action for each key > I have a hash table of several items. > > What I would like to do is loop through the hash and do a different > action based on each unique key. [...] > Can you please point into the right direction of how to go about solving > this problem. Maybe you can adapt the following pattern to your needs: actions = { :a => lambda{|*args| puts "action 'a' called with #{args}" }, :b => lambda{|*args| puts "action 'b' called with #{args}" } } myhashtable= {:a => 'foo', :b => 'moo'} myhashtable.each {|k, v| actions[k].call(v)} -- Anurag Priyam http://about.me/yeban/