When you put a Proc
object pr
with &
in the last argument position such as in:
some_method(&pr)
then, a block corresponding to pr
will be passed to some_method
. If an object non_pr
that is not a Proc
is given like:
some_method(&non_pr)
then, non_pr
will be implicitly converted to a Proc
by to_proc
.
For example, when non_pr
is a Symbol
, then Symbol#to_proc
will be applied, which happens to be something like this:
class Symbol
def to_proc
proc{|obj, *args| obj.send(self, *args)}
end
end
Particularly with each(&:delete_all)
, the :delete_all.to_proc
will return the Proc
object:
proc{|obj, *args| obj.delete_all(*args)}
so the corresponding block will be passed to each
like this:
each{|obj, *args| obj.delete_all(*args)}
Noticing that the arity of a block for Enumerable#each
is one, this is simplified to:
each{|obj| obj.delete_all}