Skip to content


find-ref command #779

rking opened this Issue · 4 comments

4 participants


Let's say you have an object that you know is getting referenced, but you have no clue by what thing.

find-ref x

Bonus points if it doesn't also show the x being passed in.

search_space = local_vars + + all_ivars + all_constants + all_globals + ObjectSpace.each_object(Proc) { |p| p.binding }


I recommend closing this issue because of it's age.


Played with the idea a little bit ( but it seems like this will be super fragile:

  • This finds closures (capture the local) and objects (capture the ivar) but we can see did not find itself, for that, I think we have to look at stack frames. And I don't know of any way to do that from Ruby-land
  • Any object that doesn't store its data in an ivar will need something explicitly written to handle this (e.g. Array, Hash, Struct, etc)
  • It's pretty heavy (iterates through ObjectSpace multiple times)
  • It's inherently prone to certain bugs (ie if it could traverse stack frame, it would find itself)
  • We could maybe use some of Ruby's methods to get it more reliable ( but even the docs say it's experimental and MRI only. Plus, some playing around with it found some pretty serious hurdles

I like the idea a lot (anything to demystify the Object web), but think it would be better to wait for someone to implement this finding functionality independently of Pry, then reconsider.

pry member

I implemented with a patch to ruby (described Using reachable_objects_from and the approach used there to discard references kept by the library itself is probably feasible, but should probably be implemented as a plugin not in core pry (as it would be MRI only)


Thaaaaat is fucking cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.