Converting to Proc

suggest change

Objects that respond to to_proc can be converted to procs with the & operator (which will also allow them to be passed as blocks).

Symbol defines #to_proc, so the symbol is called as a method on each object it receives.

p [ 'rabbit', 'grass' ].map( &:upcase ) # => ["RABBIT", "GRASS"]

Method objects also define #to_proc.

output = method( :p )

[ 'rabbit', 'grass' ].map( &output )
# prints "rabbit" and "grass" (p uses inspect), and returns ["rabbit", "grass"]

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents