From: Martin DeMello Date: 2005-05-12T05:20:28+09:00 Subject: Re: alternatives to ? : contruct Joel VanderWerf wrote: > > Just kidding: > > class Object > def incase(cond) > if cond > self > else > yield > end > end > end > > a = 3.incase(1==2) {"c"} > p a > a = 3.incase(1==1) {"c"} > p a That's only lazy in its second argument :) Maybe def only(&block) block end class Proc def if(arg) arg ? self.call : arg end end class Object def then self ? yield : self end def else self ? self : yield end alias :otherwise :else end p (1==1).then { 5 }.else { 1/0 } p only {1/0}.if(1 == 2).otherwise { 4 } martin