Skip to content

Instantly share code, notes, and snippets.

/0.rb Secret

Created July 6, 2013 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a4bb112e09f8102a58e4 to your computer and use it in GitHub Desktop.
Save anonymous/a4bb112e09f8102a58e4 to your computer and use it in GitHub Desktop.
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