Skip to content

Instantly share code, notes, and snippets.

@NathanZook
Created March 20, 2014 20:16
Show Gist options
  • Save NathanZook/9672895 to your computer and use it in GitHub Desktop.
Save NathanZook/9672895 to your computer and use it in GitHub Desktop.
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