From: Robert Klemme Date: 2011-04-04T16:36:33+09:00 Subject: Re: pipe question On Mon, Apr 4, 2011 at 5:08 AM, John Feminella wrote: > An expression like "foo || bar" works like this: First, evaluate the > boolean value of `foo`. If it is boolean-true, then the value of this > expression is `foo`. If not, then the value of this expression is > `bar`. > > This expression says, assign the current value of @first_name back > into @first_name. Alternatively, if this is the first time you're > trying to assign it, it'll be nil, so use an empty string instead. > > It's equivalent to writing: > >    @first_name ||= '' No. That is equivalent to: @first_name || @first_name = "" which is not the same as @first_name = @first_name || "" See also irb(main):004:0> x=Object.new => # irb(main):005:0> def x.[](k) puts "get";@x;end => nil irb(main):006:0> def x.[]=(k,v) puts "put";@x=v;end => nil irb(main):007:0> x[1] ||= 2 get put => 2 irb(main):008:0> x[1] ||= 2 get => 2 This has been discussed at lengths here in the past. You should be able to find plenty of evidence. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/