Created
July 31, 2009 17:34
-
-
Save fgalassi/159338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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