From: "Peña, Botp" Date: 2007-09-05T13:37:32+09:00 Subject: Re: assigning to hash keys when there is a default value? From: Robert Klemme [mailto:shortcutter@googlemail.com] # 2007/9/4, Yossef Mendelssohn : # > If '"x+=1" will always be "x=x+1"', what's the problem in # having x ||= # > 1 always be x = x || 1? # That an assignment of x=x is useless (basically a nop in the standard # case of x being a variable). consider, irb(main):074:0* h=Hash.new => {} irb(main):075:0> h[5] = h[5] => nil irb(main):076:0> h => {5=>nil} irb(main):062:0* h=Hash.new(1) => {} irb(main):063:0> h[5] = h[5] => 1 irb(main):064:0> h => {5=>1} thus h[k] = h[k] could mean h[k] = h.default or h[k] = nil definitely not useless and not noop. seeking enlightenment -botp