pry非常适合调试BasicObject的子类!
https://github.com/pry/pry说撬具有:
“外来对象支持(BasicObject实例……”
但是怎么做呢?
可以预料,BasicObject不理解绑定.
NameError: undefined local variable or method `binding' for #<C30Course:0xbefbc0c>
调用method_missing时,何处发送绑定?
解决方法
您需要直接在Kernel上调用绑定方法,如下所示:
[13] pry(main)> class O < BasicObject | def hi | x = 10 | ::Kernel.binding.pry | end | end => nil [14] pry(main)> O.new.hi From: (pry) @ line 19 O#hi: 17: def hi 18: x = 10 => 19: ::Kernel.binding.pry 20: end [1] pry(unknown)> x => 10 [2] pry(unknown)> self => #<O:0x3fd5310d04f8>