h = Hash.new { |hash, key| hash[key] = [] } h["even"] << 2222 h["even"] << 4444 h["odd"] << 111 h["odd"] << 333 p h #=> {"even"=>[2222, 4444], "odd"=>[111, 333]}