[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is there a better way to write { yield }

Stephan Wehner

5/20/2008 10:58:00 PM

Is there a better way to write something like

def meth(a,b,c)
:
:
other_meth(d) { yield }
:
:
end

That { yield } has some redundancy.

Thanks

Stephan
--
Posted via http://www.ruby-....

2 Answers

ara.t.howard

5/20/2008 11:39:00 PM

0


On May 20, 2008, at 4:58 PM, Stephan Wehner wrote:

> Is there a better way to write something like
>
> def meth(a,b,c)
> :
> :
> other_meth(d) { yield }
> :
> :
> end
>
> That { yield } has some redundancy.
>
> Thanks
>
> Stephan
> --
> Posted via http://www.ruby-....
>



def meth(*a, &b)
other_method(*a, &b)
end


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Joel VanderWerf

5/21/2008 3:29:00 AM

0

Stephan Wehner wrote:
> Is there a better way to write something like
>
> def meth(a,b,c)
> :
> :
> other_meth(d) { yield }
> :
> :
> end
>
> That { yield } has some redundancy.

That form has the advantage, IIUC, that no Proc object is created, so
it's a little more efficient. (Search the archives for block versus
proc.) Also, Rdoc can pick up the yield (and its arg) automatically.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407