Create the new hash from the old one with Ruby -
i have simple_hash:
old_hash = {"new"=>"0"}
i wan convert new format:
new_hash = old_hash.keys.each |key| hash = hash.new hash[key] = {count: old_hash[key]} hash end
but code returns me:
["new"]
instead of:
{"new"=>{:count=>"0"}}
and question why?
you confusing syntax of block of method. in code, new_hash
gets value of old_hash.keys
, not want.
a little modification works:
new_hash = hash.new old_hash.keys.each |key| new_hash[key] = {count: old_hash[key]} end
Comments
Post a Comment