Thursday, April 17, 2014
Block Procs Lambdas map&:(to_s) &:
How &: works? if it is a method, and where is it defined?
> It is rails addition to ruby obviously.
http://caboo.se/doc/classes/Symbol.html#M003931
Symbol#to_proc
This is tricky thing to document. It exploits a ruby syntax quirk where
prepending a & to a method argument calls "to_proc" on that object in an
attempt to make it eligible to be a block.
v.map(&:to_s)
Is the same as:
v.map { |i| i.to_s }
https://www.ruby-forum.com/topic/154453
http://www.reactive.io/tips/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment