[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Newbie question: Small blocks

Joel VanderWerf

9/10/2007 7:38:00 PM

Dante Regis wrote:
> Hello folks,
>
> sorry for this newbie question, but I saw somewhere that there is a way to
> make a small block without using pipes " | ".
>
> It was something like [0, 1, 2].each { } , with some char inside the
> brackets, like &, but I can't remember it. anyone knows how to use it?

Maybe this?

class Symbol
def to_proc
proc {|x,*args| x.send(self, *args)}
end
end

[1,2,3].map(&:to_s) # ==> ["1", "2", "3"]

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

1 Answer

Phlip

9/10/2007 7:45:00 PM

0

Joel VanderWerf wrote:

> [1,2,3].map(&:to_s) # ==> ["1", "2", "3"]
> proc {|x,*args| x.send(self, *args)}

*args?! Nobody told me you could pass args in too!

--
Phlip
http://www.oreilly.com/catalog/9780...
^ assert_xpath
http://tinyurl.... <-- assert_latest Model