Hacker News new | ask | show | jobs
by sirn 3460 days ago
Yes.

    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