Created
March 20, 2014 20:16
-
-
Save NathanZook/9672895 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
class R | |
def initialize | |
@methods = {} | |
end | |
def method(name) | |
@methods[name] | |
end | |
def declare(name, &blk) | |
@methods[name] = blk | |
end | |
end | |
class C | |
def initialize(r, x) | |
@r = r | |
@x = x | |
end | |
def method_missing(meth, *args) | |
instance_exec(*args, &@r.method(meth)) | |
end | |
end | |
r = R.new | |
r.declare(:x){|a| puts a + @x} | |
c = C.new(r, 2) | |
c.x(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment