From: Rein Henrichs Date: 2010-06-08T02:05:28+09:00 Subject: Re: Question about abbreviated indexing assignments On 2010-06-07 08:42:08 -0700, J�rg W Mittag said: > h[:key] ||= :value > # "Setting key to value" > h[:key] ||= :value > > But this doesn't. > > Since the purpose of the specification is to describe the currently > existing implementations, this is obviously a bug in the specification > rather than a bug in all five currently released implementations, > especially since there is a ton of code and even a common idiom that > depends on the current behavior. But what would the correct > specification look like? > > Thanks in advance, > J�rg. It is commonly thought that x = y is exactly equivalent to x = x y in all cases. What you have just demonstrated is that, presumably for performance reasons, h[key] ||= value is in fact equivalent to h[key] || h[key] = value, rather than h[key] = h[key] || value. This prevents a second lookup in the case where k[key] exists and is not nil or false. As to what the correct specification would look like, I am not sure, but I do agree with you. -- Rein Henrichs http://puppetlabs.com http://reinh.com