元编程的问题

元编程的问题

能说一下下面代码的运行过程和 那产生的代码的样子吗?

[Copy to clipboard] [ - ]
弄懂method_missing的用法就能理解这个了
首先查ri或者其他文档
引用:
>ri Kernel#method_missing
-------------------------------------------------- Kernel#method_missing
  obj.method_missing(symbol [, *args] ) => result
------------------------------------------------------------------------
  Invoked by Ruby when _obj_ is sent a message it cannot handle.
  _symbol_ is the symbol for the method called, and _args_ are any
  arguments that were passed to it. By default, the interpreter
  raises an error when this method is called. However, it is possible
  to override the method to provide more dynamic behavior. The
  example below creates a class +Roman+, which responds to methods
  with names consisting of roman numerals, returning the
  corresponding integer values.

   class Roman
    def romanToInt(str)
    # ...
    end
    def method_missing(methId)
    str = methId.id2name
    romanToInt(str)
    end
   end

   r = Roman.new
   r.iv  #=> 4
   r.xxiii #=> 23
   r.mm  #=> 2000