Hi, From: "ako..." <akonsu / gmail.com> > > i am still learning. in the below code @attributes is a hash table. i > want to add a new value 'a' for a key represented by 'a.key'. i also > want to group values with the same keys in to arrays. thanks for any > help. > > if @attributes.has_key?(a.key) > if @attributes[a.key].is_a?(Array) > @attributes[a.key] << a > else > @attributes[a.key] = [@attributes[a.key], a] > end > else > @attributes[a.key] = a > end An alternate approach might be: @attributes = Hash.new {|h,k| h[k] = Array.new} This will automatically create arrays to hold your keys, on demand. Now you can just say: @attributes["whatever"] << "something" @attributes["foo"] << 123 @attributes["foo"] << 456 @attributes.inspect {"foo"=>[123, 456], "whatever"=>["something"]} Hope this helps, Regards, Bill