87a655824efaa262301db827a292e1b791639a8c — Edward Loveall 2 months ago 637751f
Add local_caller method

Sometimes you want a stack trace of what chain of methods invoked
wherever you are right now. `caller` does this, but it also includes
things like library and irb/pry frames in the stack. Often what I want
is the stack frames from whatever code is in the current code base.

`local_caller` uses the current directory as a proxy for "current code
base". It `select`s the frames that contain `Dir.pwd` which leaves us
with a nice, small stack trace.

This is on `Kernel` so it can be uses anywhere.
1 files changed, 6 insertions(+), 0 deletions(-)

M configs/dot-irbrc
M configs/dot-irbrc => configs/dot-irbrc +6 -0
@@ 13,3 13,9 @@ class String
    IO.popen("pbcopy", "w") { |copy| copy.puts(self) }

module Kernel
  def local_caller
    caller.select { |line| line.include?(Dir.pwd) }