Last active
August 29, 2015 13:56
-
-
Save threeifbywhiskey/8893626 to your computer and use it in GitHub Desktop.
Enumerabull pollutes Kernelspace with inverted versions of Enumerable's instance methods. It's like unleashing a bull in your Ruby shop to get "functional programming".
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 Kernel | |
Enumerable.instance_methods.each do |meth| | |
define_method(meth) do |*args| | |
obj = args.pop | |
case pred = args.first | |
when Proc, Symbol | |
obj.send meth, *args.drop(1), &pred | |
else | |
obj.send meth, *args | |
end | |
end | |
end | |
alias each each_entry | |
end | |
p reduce :+, 10, 1..10 | |
p select :even?, 1..10 | |
each->n { p n }, 1..10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment