New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find-ref command #779

rking opened this Issue Dec 12, 2012 · 4 comments


None yet
4 participants

rking commented Dec 12, 2012

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 }


This comment has been minimized.

JackDanger commented Jul 18, 2014

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


This comment has been minimized.


JoshCheek commented Aug 17, 2014

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.


This comment has been minimized.


ConradIrwin commented Aug 17, 2014

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)


This comment has been minimized.


JoshCheek commented Aug 17, 2014

Thaaaaat is fucking cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment