Module: Corefines::Enumerable::MapSend

Defined in:
lib/corefines/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#map_send(method_name, *args, &block) ⇒ Enumerable

Sends a message to each element and collects the result.

Examples:

[1, 2, 3].map_send(:+, 3) #=> [4, 5, 6]

Parameters:

  • method_name (Symbol)

    name of the method to call.

  • args

    arguments to pass to the method.

  • block (Proc)

    block to pass to the method.

Returns:


131
132
133
134
135
136
137
138
139
140
# File 'lib/corefines/enumerable.rb', line 131

module MapSend
  Support.classes_including_module(::Enumerable) do |klass|

    refine klass do
      def map_send(method_name, *args, &block)
        map { |e| e.__send__(method_name, *args, &block) }
      end
    end
  end
end