-
-
Save anonymous/a4bb112e09f8102a58e4 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
def make_awesome meth | |
proc do |*args, &block| | |
block ||= -> elem { elem.send *args } | |
send meth, &block | |
end | |
end | |
def patch_the_monkey | |
%w[map select].each do |m| | |
alias_method m * 2, m | |
define_method m, make_awesome(m * 2) | |
end | |
end | |
class Array | |
patch_the_monkey | |
end | |
module Enumerable | |
patch_the_monkey | |
end | |
p (1..10).map :to_s, 2 | |
p [1,2,3].select :>, 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment