I want to track the counts of some elements with an arbitrary name, and then reset the numbers to zero. My thought was this:
reset_hash={"string1"=>0,"string2"=>0,"string3"=>0}
=> {"string1"=>0, "string2"=>0, "string3"=>0}
new_hash = reset_hash
=> {"string1"=>0, "string2"=>0, "string3"=>0}
new_hash["string1"]=1
new_hash["string3"]=1
new_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
...
Now I want to reset new_hash back to reset_hash:
new_hash = reset_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
reset_hash
=> {"string1"=>1, "string2"=>0, "string3"=>1}
What's going on here? It seems that reset_hash really was set to new_hash, which is the opposite of what I wanted. How to implement the desired behavior?
source
share