4 ms·
Sure. require 'pry' module Kernel def debug; binding.pry; end end x = "hi" debug
by fidz 10y ago
Sure.
require 'pry'
module Kernel
def debug; binding.pry; end
end
x = "hi"
debug
- gkop 10y agoI was imagining more at the level of the standard library or the pry library. Or do you recommend this monkeypatch in practice?
- lparry 10y agoWon't the binding then be your monkey patched debug method on kernel instead of where you called it from?
- sirn 10y agoYes. irb(main):008:0> x = "1" => "1" irb(main):009:0> debug [1] pry(main)> x NameError: undefined local variable or method `x' for main:Object from (pry):1:in `debug' If you really want to do this, you can use binding_of_caller[1] to create binding object (`Kernel.binding`) up in the call stack: require 'binding_of_caller' require 'pry' module Kernel def debug binding.of_caller(1).pry end end Then: irb(main):008:0> x = "1" => "1" irb(main):009:0> debug [1] pry(main)> x => "1" [1]: https://github.com/banister/binding_of_caller https://github.com/banister/binding_of_caller