From: Robert Klemme Date: 2008-05-02T04:25:08+09:00 Subject: Re: Please explain nuances of ||= On 01.05.2008 20:54, Simon Krahnke wrote: > * David A. Black (18:56) schrieb: > >> Hi -- >> >> On Fri, 2 May 2008, Ruby Freak wrote: >> >>> I am reading some of the ruby files in rails and I an seeing the ||= >>> method used a lot. >>> knowing ruby the way I do, I realize that she has lots of magical >>> surprises and I really want to get to know this girl! >> x ||= y means: x || x = y > > No, it means: x = x || y I believe you are wrong. irb(main):001:0> h={} => {} irb(main):002:0> h=Hash.new true => {} irb(main):003:0> h[1] => true irb(main):004:0> h[1] ||= 10 => true irb(main):005:0> h => {} irb(main):006:0> If you were right, h would look differently: irb(main):008:0> h=Hash.new true => {} irb(main):009:0> h[1] = h[1] || 10 => true irb(main):010:0> h => {1=>true} The same topic has been discussed exhaustively a few days ago. Cheers robert