@@ -212,6 +212,31 @@ def test_show_class_of_subclasses_of_simple_types
212212      assert_includes  @inspector . named_members_of ( hash_subclass . new ) ,  Variable . internal ( name : "#class" ,  value : hash_subclass ) 
213213    end 
214214
215+     def  test_debug_representation_hook 
216+       object_with_simple_repr  =  ClassWithCustomDebugRepresentation . new ( {  a : 1 ,  b : 2  } ) 
217+ 
218+       expected  =  [ 
219+         # We should always show the `#class` when using this hook, even if the 
220+         # debug_representation is a simple value. 
221+         Variable . internal ( name : '#class' ,  value : ClassWithCustomDebugRepresentation ) , 
222+         Variable . new ( name : ':a' ,  value : 1 ) , 
223+         Variable . new ( name : ':b' ,  value : 2 ) , 
224+       ] 
225+ 
226+       assert_equal  expected ,  @inspector . named_members_of ( object_with_simple_repr ) 
227+ 
228+       object_with_complex_repr  =  ClassWithCustomDebugRepresentation . new ( Point . new ( x : 1 ,  y : 2 ) ) 
229+ 
230+       expected  =  [ 
231+         # Make sure we don't add the '#class' twice for non-simple debug representations 
232+         Variable . internal ( name : '#class' ,  value : ClassWithCustomDebugRepresentation ) , 
233+         Variable . new ( name : :@x ,  value : 1 ) , 
234+         Variable . new ( name : :@y ,  value : 2 ) , 
235+       ] 
236+ 
237+       assert_equal  expected ,  @inspector . named_members_of ( object_with_complex_repr ) 
238+     end 
239+ 
215240    private 
216241
217242    class  PointStruct  < Struct . new ( :x ,  :y ,  keyword_init : true ) 
@@ -227,5 +252,15 @@ def initialize(x:, y:)
227252        @y  =  y 
228253      end 
229254    end 
255+ 
256+     class  ClassWithCustomDebugRepresentation 
257+       def  initialize ( debug_representation ) 
258+         @debug_representation  =  debug_representation 
259+       end 
260+ 
261+       def  debug_representation 
262+         @debug_representation 
263+       end 
264+     end 
230265  end 
231266end 
0 commit comments