From: Jeff Wood Date: 2006-06-12T14:32:26+09:00 Subject: Re: ... building my own end-fix statements. Yeah, that's a lot closer to what I was thinking. thanks... Had forgotten about doing a . after the block ... really darn'd close. --jw. On 6/11/06, Logan Capaldo wrote: > > On Jun 9, 2006, at 4:44 PM, Jeff Wood wrote: > > > I believe it's possible to define my own end-fix qualifiers like "if" > > and "unless" ... > > > > Can anybody provide code examples for defining such a construct in > > Ruby? > > > > For instance : > > > > x.doSomething() when x.ready? > > > > which would call x.ready? repeatedly until it returned a true then > > would call x.doSomething() > > > > ... I know I could do > > > > while( not x.ready? ) > > sleep 0.5 > > wend > > > > x.doSomething() > > > > but I'd rather not. > > > > even a > > > > when( x.ready? ) { |result| x.doSomething() } would be fine I guess > > ... but wouldn't work because x.ready? would be precalculated before > > when gets to it... so it wouldn't ever change... I basically need to > > be able to pass two blocks if I were to do this ... > > > > when( isReadyProc, bodyProc ) ... or something like that. > > > > Any ideas ??? > > > > --jw. > > > > I called it "after" since when is a keyword: > > % cat after.rb > class After > def initialize(&block) > @test = block > end > > def do > until @test.call > sleep 0.5 > end > > yield > end > end > > module Kernel > private > def after(&block) > After.new(&block) > end > end > > class X > def initialize > @x = 0 > end > > def ready? > if @x == 10 > true > else > @x += 1 > false > end > end > end > > x = X.new > after { x.ready? }.do { > puts "x is finally ready!" > } > > > > > > % ruby after.rb > x is finally ready! > > >