From: luke gruber Date: 2011-11-07T12:01:13+09:00 Subject: Re: Tricky DSL, how to do it? Sorry 'bout the double posting, but it hit me that it's only impossible to bind a method to an instance that's of the same class. That and the fact that the whole binding thing was useless in my previous post made me go back to my computer and give it another shot. It's still not a great solution, because I couldn't figure out how to inherit from BasicObject and still have it work. class Evaluator < Object attr_reader :__config__, :__outside__ def initialize(outside, &block) @__config__ = {} @__outside__ = outside instance_eval &block end def method_missing(sym, *args, &block) if block_given? outside = @__outside__ outside.class.class_eval do define_method sym do |*args| outside.instance_exec *args, &block end end @__config__[sym] = @__outside__.method(sym) else super end end end class Test def hunt puts "DEAD" end end t = Test.new e = Evaluator.new(t) do foo do puts "foo" end baz do hunt end end e.__config__[:foo].call e.__config__[:baz].call -Luke -- Posted via http://www.ruby-forum.com/.