./ruby/test/mymap.rb

download original
module Enumerable
  def mymap(&block)
    slf = self
    Class.new {
      include Enumerable
      define_method(:each) {
        slf.each do |elt|
          out = block.call(elt)
          puts "#{elt} => #{out}"
          yield(out)
        end
      }
    }.new
  end
end

  
back to test

(C) 1998-2017 Olaf Klischat <olaf.klischat@gmail.com>