Possible Duplicate:
What does map(&:name) mean in Ruby?
What do you call the &: operator in Ruby?
Just watching some railscast and see code like this:
[Category, Product, Person].each(&:delete_all)
I know that it erases all records for these models, but I can't find out what this &:delete_all
means.
It's basically shorthand for this:
[Category, Product, Person].each { |e| e.delete_all }
That is, it sends delete_all
to each element of the iterator.
&:delete_all basically translates to |obj| obj.delete_all. The ampersand calls to_proc on the current object on the loop.
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