> Any ideas?

This might not be the best solution, but if you give initialize
an argument about its surrounding state, then it becomes easier.


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__.class.class_eval do
        define_method sym do |*args|
          block.call *args
        end
      end
      @__config__[sym] = 
@__outside__.class.instance_method(sym).bind(self)
    else
      super
    end
  end

end

e = Evaluator.new(self) do
  foo do
    puts "foo"
  end
end

e.__config__[:foo].call

I don't know if that's what you were after, but after playing around
for a bit that's what I came up with.

Let me know if it helps,

-Luke

-- 
Posted via http://www.ruby-forum.com/.