From: Dominik Honnef Date: 2010-06-15T08:54:50+09:00 Subject: Re: shorthand Roger Pack writes: > 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? > -r Sure you don't mean ||= as a way of easily implementing basic memoization? Example: class Foo def bar @bar ||= begin # do some calculations here 1 + rand end end end f = Foo.new f.bar # => 1.01853966346202 f.bar # => 1.01853966346202