Converting to Proc
suggest changeObjects 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"]
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents