Mapping with hash keys
I work with my_hash hash:
{"2011-02-01 00:00:00+00"=>816, "2011-01-01 00:00:00+00"=>58, "2011-03-01 00:00:00+00"=>241}
Firstly, I am trying to parse all the keys in my_hash (which are times).
my_hash.keys.sort.each do |key| parsed_keys << Date.parse(key).to_s end
What gives me this:
["2011-01-01", "2011-02-01", "2011-03-01"]
Then I try to map parsed_keys to my_hash keys:
Hash[my_hash.map {|k,v| [parsed_keys[k], v]}]
But this returns the following error:
TypeError: can't convert String into Integer
How can I map parsed_keys to my_hash keys?
My goal is to get rid of the “00: 00: 00 + 00” at the end of all the keys.
There is a new "Rails way" method for this task :)
http://api.rubyonrails.org/classes/Hash.html#method-i-transform_keys