From: Brian Candler Date: 2010-06-16T02:24:19+09:00 Subject: Re: shorthand Roger Pack wrote: > I read this once: > > Operator ||= can be shorthand for code like: > x = "(some fallback value)" unless respond_to? :x or x > > How would that look like exactly, in shorthand, any guesses? foo ||= 5 is shorthand for foo = foo || 5 which means (a) 'foo' is a local variable (because it's an assignment) (b) it will be set to 5 if it is currently nil or false, otherwise it will retain its previous value. The thing you read about respond_to? is wrong. This construct is nothing to do with a method called foo, as you can easily demonstrate: $ irb --simple-prompt >> def foo >> 9 >> end => nil >> respond_to? :foo => true >> foo ||= 5 => 5 >> foo => 5 -- Posted via http://www.ruby-forum.com/.