Understanding [ClassOne, ClassTwo].each(&:my_method) [duplicate]

Solution 1:

This relies upon a Ruby 1.9 extension that can be done in 1.8 by including the following:

class Symbol
    def to_proc
      proc { |obj, *args| obj.send(self, *args) }
    end
end

I believe Rails defines this in ActiveSupport.

Solution 2:

It's some Rails specific patching of Ruby, symbol to proc.