Module: Corefines::Enumerable::MapTo

Defined in:
lib/corefines/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#map_to(klass) ⇒ Enumerable

Maps each element of this enum into the klass via constructor.

Examples:

['/tmp', '/var/tmp'].map_to(Pathname) # => [#<Pathname:/tmp>, #<Pathname:/var/tmp>]

153
154
155
156
157
158
159
160
161
162
# File 'lib/corefines/enumerable.rb', line 153

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

    refine klass do
      def map_to(klass)
        map { |e| klass.new(e) }
      end
    end
  end
end