1

As part of my debugging, I need to dump out a big object. Some of the data shows up like this:

#<Sketchup::Face:0x00007f9119bafea8>

This is the result of calling .inspect on the Sketchup::Face object, and Ruby calls .inspect internally when things are printed to the console.

Is it possible to then get a reference to the actual instance, using that 0x00007f9119bafea8 identifier? I don't even know exactly what this is - a pointer, instance id, something else?

Of course I can always manipulate my data before printing to console but since this is just for temporary debugging I'm hoping there's a quick and easy way.

Note: normally I would put in a binding.pry to avoid this whole business but due to Sketchup's restrictive programming environment it's not possible to use breakpoints there.

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • There’s [`ObjectSpace::_id2ref`](https://ruby-doc.org/core-2.6.1/ObjectSpace.html#method-c-_id2ref) (linking to older docs because the description is missing in the new ones) – Stefan May 03 '22 at 20:56
  • Aye, yeah but `0x00007f9804844a10` isn't an object id – max pleaner May 03 '22 at 21:12
  • I’d try to reconstruct the object id (see [here](https://stackoverflow.com/q/2818602/477037)). If that doesn’t work, override `inspect` to print the actual object id. – Stefan May 04 '22 at 04:56
  • If my C reading is correct, this is the physical address of the object in the memory. Since ruby has no explicit pointer I'd say it is useless, would be happy to be proven wrong though. – BroiSatse May 04 '22 at 21:30
  • Combining the information given in the comments above, you can get a refence to the object with a inspect output of `#` using `ObjectSpace::_id2ref(0x000000000d4f07b0 >> 1)` – sapphyrus May 06 '22 at 21:15

0 Answers0