[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to use the *args in to_proc ?

Phlip

2/7/2008 4:17:00 PM

Jeremy Kemper wrote:

> > Sure. &:position == :position.to_proc == proc { |element, *args|
> > element.position(*args) }
> >
> > So elements.sort_by(&:position) is shorthand for sorting the elements by
> > position.

How would you pass the *args in?? They don't seem to fit on either side
of the &, which is "special" in argument passing syntax...

-- Phlip
1 Answer

Clifford Heath

2/7/2008 10:44:00 PM

0

Phlip wrote:
> Jeremy Kemper wrote:
>
> > > Sure. &:position == :position.to_proc == proc { |element, *args|
> > > element.position(*args) }
> > >
> > > So elements.sort_by(&:position) is shorthand for sorting the
> elements by
> > > position.
>
> How would you pass the *args in?? They don't seem to fit on either side
> of the &, which is "special" in argument passing syntax...

You can't. If you need to, you should hand-roll something like Jeremy's
third case.

Clifford Heath.