Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created June 8, 2011 10:27
Show Gist options
  • Save bil-bas/1014173 to your computer and use it in GitHub Desktop.
Save bil-bas/1014173 to your computer and use it in GitHub Desktop.
Enumerable#each_method
# 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