Created
July 13, 2009 13:05
-
-
Save judofyr/146098 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
## There's more than one way to do it. | |
# 0 | |
thing = [1, 2, 3] | |
# 1 | |
thing.each { } | |
# 2 (raggi) | |
thing.each() { } | |
# 3 | |
thing.send(:send, :send, :send, :send, :each) { } | |
# 4 (manveru) | |
thing.method(:each).__send__(:send, :call){ } | |
# 5 | |
Array.instance_method(:each).__send__(:send, :bind, thing).instance_eval { call { } } | |
# 6 | |
Array.eval(:each) { }.with(thing) | |
BEGIN { def Object.eval(m, *a, &b);r,o=self,Object.new;class << o;self;end.send(:define_method, :with){|x|r.instance_method(m).bind(x).call(*a, &b)};o end } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment