A
Abir B.
Hello,
I had to manipulate a hash (delete pairs, add pairs, )
But my problem is that the data comes sometimes as string and other
times as symbol, and this makes problems in updating the hash (sometimes
I have an entry 2 times with a symbol key and string key).
for example in this code:
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}
hash.merge(h)
=> {:g=>6, 2=>4, "g"=>5, :a=>:b}
I want that the value of hash["g"] changes to 6 without adding another
pair {:g => 6}
Someone has any idea?
thanks
I had to manipulate a hash (delete pairs, add pairs, )
But my problem is that the data comes sometimes as string and other
times as symbol, and this makes problems in updating the hash (sometimes
I have an entry 2 times with a symbol key and string key).
for example in this code:
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}
hash.merge(h)
=> {:g=>6, 2=>4, "g"=>5, :a=>:b}
I want that the value of hash["g"] changes to 6 without adding another
pair {:g => 6}
Someone has any idea?
thanks