Skip to content

Instantly share code, notes, and snippets.

@fgalassi
Created July 31, 2009 17:34
Show Gist options
  • Save fgalassi/159338 to your computer and use it in GitHub Desktop.
Save fgalassi/159338 to your computer and use it in GitHub Desktop.
module Enumerable
class MapEnumerator
instance_methods.each {|m| undef_method m unless m =~ /__/}
def initialize(enum)
@enum = enum
end
def method_missing(name, *args)
@enum.map {|e| e.send name, *args}
end
end
end
class Array
alias_method :__map__, :map
def map(&block)
if block_given?
send :__map__, &block
else
Enumerable::MapEnumerator.new self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment