From: John Feminella Date: 2011-04-04T12:08:39+09:00 Subject: Re: pipe question 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 ||= '' ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Sun, Apr 3, 2011 at 22:58, wolf volpi wrote: > What does the pipe in this example do? > >  @first_name = @first_name || '' > > According to the text book that this example came from, the code ensures > that an instance variable is not nil.  If @first_ name is nil, @first_ > name is set to the empty string. > > Thank you. > > -- > Posted via http://www.ruby-forum.com/. > >