From: Henrik Hodne Date: 2009-04-09T18:46:48+09:00 Subject: Re: Hash key : string or symbol!? You could still loop through them and make them into strings instead of symbols. new_hash = {} h.each { |k,v| new_hash[k.to_s] = v } Regards, Henrik Hodne On 9 Apr 2009, at 11:40, "Abir B." wrote: > Andrew Timberlake wrote: > >>> h = {:a => :b, 2 => 4, :g=> 6 } >>> Posted via http://www.ruby-forum.com/. >>> >>> >> >> new_hash = {} >> hash.each { |k,v| new_hash[k.to_sym] = v } >> h.each { |k,v| new_hash[k.to_sym] = v } >> > > if we have nubers in the hash that we'll be converted to nil with > to_sym > : > hash = {:a => :b, 2 => 3, "g"=> 5 } > => {2=>3, "g"=>5, :a=>:b} > h = {:a => :b, 2 => 4, :g=> 6 } > => {:g=>6, 2=>4, :a=>:b} > > new_hash = {} > => {} > hash.each { |k,v| new_hash[k.to_sym] = v } > => {2=>3, "g"=>5, :a=>:b} > h.each { |k,v| new_hash[k.to_sym] = v } > => {:g=>6, 2=>4, :a=>:b} > hash > => {2=>3, "g"=>5, :a=>:b} > h > => {:g=>6, 2=>4, :a=>:b} > new_hash > => {:g=>6, nil=>4, :a=>:b} > > And I can't control the inputs in the hash, so I must treat that by > myself > -- > Posted via http://www.ruby-forum.com/. >