title: Ruby catching NoMethodError and continue execution from where exception occurred
body: <p>In Ruby, I'd like to catch the NoMethodError generated on an object in another object, then return some value to where the exception is raised and continue execution. Is there an existing way to do this?</p>
  
  <p>The best I came up with is:</p>
  
  <pre><code>class Exception
    attr_accessor :continuation
  end
  
  class Outer
    def hello
      puts "hello"
    end
  
    class Inner
      def world
        puts "world"
      end
      def method_missing(method, *args, &amp;block)
        x = callcc do |cc|
          e = RuntimeError.exception(method)
          e.continuation = cc
          raise e
        end
        return x
      end
    end
  
    def inner(&amp;block)
      inner = Inner.new
      begin
        inner.instance_eval(&amp;block)
      rescue =&gt; e
        cc = e.continuation
        cc.call(hello())
      end
      inner
    end
  end
  
  o = Outer.new
  o.inner do
    hello
    world
  end
  </code></pre>
  
  <p>This prints</p>
  
  <pre><code>hello
  world
  </code></pre>
  
  <p>Is there a better way to do this using Ruby's existing array of meta-programming arsenal? Basically, I am not sure if callcc will continue to exist.</p>
  
  <p>Thanks.</p>