Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created July 13, 2009 13:05
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 judofyr/146098 to your computer and use it in GitHub Desktop.
Save judofyr/146098 to your computer and use it in GitHub Desktop.
## 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