Possible Duplicate:
What does map(&:name) mean in Ruby?
What does the &:valid?
found in the each
mean?
I've seen .each do |r|
or whatever, but not sure how this one works?
The &
is called the to_proc
operator. It expands the symbol (:valid?
) into a Proc.
So your example is equivalent to:
temps.each { |t| t.valid? }
&:symbol is a shorthand for symbol to proc.
Here's a good blog post on it. http://blog.hasmanythrough.com/2006/3/7/symbol-to-proc-shorthand
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With