Sometimes I am inspecting or exploring my dowmain objects which contains many instance variables. I want to exclude all of them excepting the current specific ones of the instance I am exploring.
Say I am inspecting MyObject with instance variables: text, size, status.
I want to view:
I have seen you can define the method inspectorClass, but is EyeInspector or EyeExplorer designed to configure this type of view? Should I subclass SelfEyeElement class?
I just tried and came up with this:
Imagine this is your class:
Object subclass: #MyClass
instanceVariableNames: 'firstVariable secondVariable thirdVariable'
classVariableNames: ''
category: 'MyCategory'
Then make the following inspector class:
EyeInspector subclass: #MyClassInspector
instanceVariableNames: ''
classVariableNames: ''
category: 'MyCategory'
Add the following class method to MyClass
:
inspectorClass
^ MyClassInspector
And overwrite #addInstanceVariable:
in MyClassInspector
:
addInstancesVariable: elements
elements add: (InstanceVariableEyeElement host: self object instVarName: #firstVariable).
elements add: (InstanceVariableEyeElement host: self object instVarName: #secondVariable)
Inspect an instance of MyClass
and it shows only firstVariable
and secondVariable
but not thirdVariable
:
Very nice question!
Update: If you want an inspector that shows generally only instance variables specified in the class of an inspected object and not in superclasses of an inspected object you can use this #addInstanceVariable:
in your inspector class:
addInstancesVariable: elements
self object class instVarNames do: [:name |
elements add: (InstanceVariableEyeElement host: self object instVarName: name) ]