Created
June 8, 2011 10:27
-
-
Save bil-bas/1014173 to your computer and use it in GitHub Desktop.
Enumerable#each_method
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
# calls a method many times with different args | |
# sort of an inverted Enumerable#each(&Symbol) | |
module Enumerable | |
def each_method(method_name, object = Kernel, &block) | |
each do |*args| | |
object.send(method_name, *args, &block) | |
end | |
end | |
end | |
[[1, "hello"], [2, "whee"], [3, "bye"]].each_method(:puts) | |
a = [] | |
(1..5).each_method(:push, a) | |
p a | |
# 1 | |
# hello | |
# 2 | |
# whee | |
# 3 | |
# [1, 2, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment