From: 7stud -- Date: 2007-09-03T20:21:37+09:00 Subject: Re: assigning to hash keys when there is a default value? Pe単a, Botp wrote: > they should be different (note, that has nothing to do w the bug dBlack > is pointing at) and the output should be, > > 5 > {2=>5} #<---dblack is complaining here because the ruby output is {} > > nil > {2=>10} > Yes. That is what I am complaining about too! Your are right: the second line for each section of the output should be different--I mispoke. What I want to know is why the the output is {} and not {2=>5}. The author of "The Ruby Way (2nd ed)" presents the two examples as well as the different output for each example, yet he doesn't explain the reason for the different output. He suggests that you can use ||= to selectively assign values only to keys that don't exist. The point I think he was trying to make with the two examples is that when you have a default value for non-existent keys, all keys "exist", so ||= will not create new keys with the default value. -- Posted via http://www.ruby-forum.com/.