Finding dynamic componentinstances in ruby

I’m having trouble understanding and traversing dynamic component hierarchy.

Not all components in the model I have are top level dynamic components (as seen in outliner),
some are subcomponents of other dynamic components.
When I try to access these using entity.explode in ruby there is unexpected behavior as sketchup freezes for a bit and several components get deleted, not clear why. Is there a simple way to access these subcomponents.

Solution I’m using now is to make some dynamic components of interest be at the top level. The problem with this is not all transforms occur correctly on the nested components.

Nested DC’s transformations are relative to their parent’s coordinates, so if you lift them out to another context they are not likely to work as desired.

No doubt, because that is destructive.

I am not sure if there is a foolproof way to know which sub-component instances are paired with which top component instances.