From: ara.t.howard@... Date: 2006-03-29T07:53:47+09:00 Subject: Re: Opposite of ||= pattern? On Wed, 29 Mar 2006, Justin Bailey wrote: > A cheap just-in-time initialization trick is the "||=" trick: > > def add_name(n) > @name ||= Array.new > @name << n > end > > Now, how would you do the opposite of this pattern? More specifically, what > kind of construct would evaluate to a true value once, and then nil from > then on? I came upon this in the context of for loops, where I want a > one-time "starting" value to be present the first time through the loop, > then nil. And I wanted to do it in a cool way - i.e. not just assign the > value to nil at the end of the loop, though of course that is the easiest > way. > > Any thoughts? > > Justin harp:~ > ruby -e' 3.times{ p( @x ? nil : @x=42) } ' 42 nil nil regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama