Re:(1..100).inject(&:+)
by kommissar on Monday February 25, 2008 @04:17PM
(#123350)
What does the &: do in Ruby?
[ Parent
| on HN ]
Tokens beginning with a colon are literal Ruby symbols.
Prepending an ampersand before the last argument of a method call means that argument should be converted into a Proc and sent as a callback block to that method.
Actually, it's &(:+) not &:(+). The & takes its argument and converts from a Proc to a block. :+ is a symbol that implements the method #to_proc to give you a block that sums its receiver and its argument.