question about pickaxe code example

C

Chuck Taylor

in chapter 12 of pickaxe in the tutthreads_10.rb example there is a line

threads.each(&:join)

that appears to be doing what you would expect from the line

threads.each {|t| t.join}

I'm wondering if anyone could point me at a more general description of
how this bit of code is doing something like turning a symbol into a
code block? (this is totally a guess on my part)

Thanks for any light that you can shed on the matter.

-chuck
 
B

Brian Candler

Chuck said:
in chapter 12 of pickaxe in the tutthreads_10.rb example there is a line

threads.each(&:join)

that appears to be doing what you would expect from the line

threads.each {|t| t.join}

I'm wondering if anyone could point me at a more general description of
how this bit of code is doing something like turning a symbol into a
code block? (this is totally a guess on my part)

You're right, and Symbol#to_proc is what to Google for to get the full
details.

http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top