我正在尝试按以下方式扩展Method类:
irb(main):008:0> class A
irb(main):009:1> def a
irb(main):010:2> puts "blah"
irb(main):011:2> end
irb(main):012:1> end
=> nil
irb(main):013:0> class Method
irb(main):014:1> def aa
irb(main):015:2> p "hi"
irb(main):016:2> end
irb(main):017:1> end
=> nil
irb(main):018:0> f = A.new
=> #<A:0x54ed4>
irb(main):019:0> A.a
NoMethodError: undefined method `a' for A:Class
from (irb):19
from :0
irb(main):020:0> f.a
blah
=> nil
irb(main):027:0> f.a.aa
blah
NoMethodError: undefined method `aa' for nil:NilClass
from (irb):27
from :0
正如预期的那样,当我f.a.aa
时,.aa
正在f.a
的返回值上执行。如何访问表示f.a
?