#1220·pry

whereami gets confused in a Dir.chdir block

Author: dtenenbaCreated May 4, 2014Updated Oct 1, 2025

Hello, I have the following script foo.rb:

require 'tmpdir'
require 'pry'

tmpdir = Dir.mktmpdir

Dir.chdir tmpdir do
     puts "type whereami now"
     binding.pry
end

If I run it like this:

ruby foo.rb

Then when I get dropped into pry I type 'whereami' and see:

[1] pry(main)> whereami
Error: Cannot open "/private/var/folders/jz/_76qjszd4db7drk0sm2vfn5h0000gn/T/d20140504-37098-1vehyq/foo.rb" for reading.

Is there any way around that? Can whereami work off the directory it was in when the script was invoked, not the one it's in when binding.pry is invoked?

I also use pry as a debugger with pry-nav, and experience the same problem when I step into a Dir.chdir block.