Skip to main content
Engineering LibreTexts

7.3: The Inspector

  • Page ID
    39607
    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    One of the things that makes Pharo so different from many other programming environments is that it provides you with a window onto a world of live objects, not a world of static code. Any of those objects can be examined by the programmer, and even modified (although some care is necessary when changing the basic objects that support the system). By all means experiment, but save your image first!

    As an illustration of what you can do with an inspector, type DateAndTime now in a playground, and then right-click and choose Inspect it (CMD-i) or Do it and go (CMD-g) (the latter opens an inspector inside the playground window).

    Note that it’s often not necessary to select the text before using the menu; if no text is selected, the menu operations work on the whole of the current line.

    A window like that shown in Figure \(\PageIndex{1}\) will appear. This is an inspector, and can be thought of as a window onto the internals of a particular object – in this case, the particular instance of DateAndTime that was created when you evaluated the expression DateAndTime now. The title bar of the window shows the printable representation of the object that is being inspected.

    Inspecting DateAndTime now.
    Figure \(\PageIndex{1}\): Inspecting DateAndTime now.

    In the default view (the Raw tab), instance variables can be explored by selecting them in the variable list in the Variable column. As you select a variable, its printable representation is shown in the Value column. More importantly, a separate Inspector view for the selected variable opens in the right hand pane.

    For variables that are simple types (booleans, integers, etc), the nested inspector view is not much different from the printable representation in the Value column (although it is a full-fledged Inspector). But for most instance variables, the nested Inspector view on the right has its own Raw tab, with its own list of instance variables. (You can also see that list in the left pane, by expanding the triangle next to a variable’s name.)

    You can keep drilling down into the hierarchy of instance variables, with more nested Inspector panes opening to the right of the parent. However, to prevent the multiple panes from being impractical, the panes ”scroll” to the right, within the overall inspector window. You can keep track of which ”page” you’re on, and also back-track to the original instance that you were inspecting, by using the pagination dots at the bottom of the inspector window.

    There are special variants of the inspector for Dictionaries, OrderedCollections, CompiledMethods and a few other classes. These variants have other tabs, in addition to the Raw view, that make it easier to examine the contents of these special objects. For example, an inspector on a Dictionary instance, has an additional Items tab that shows that dictionary’s keys and values in an intuitive fashion.

    The horizontal pane at the bottom of the inspector is a small playground window. It is useful because in this window, the pseudo-variable self is bound to the object that you have selected in the left pane. That means you can write and evaluate arbitrary code expressions that use the selected variable’s self, in that bottom pane.

    For example, take the inspector on DateAndTime now that you opened earlier in this section. You can select its bottom playground pane, and evaluate the expression self - DateAndTime today. The result will be a Duration object that represents the time interval between midnight today and the instant at which you evaluated DateAndTime now and created the DateAndTime instance that you are inspecting. You can also try evaluating DateAndTime now - self; this will tell you how long you have spent reading this section of this book!

    The bottom pane is especially useful if you wanted to change the instance variables of the object being inspected. Provided that you have accessor methods defined for those variables, you can send messages to the root self and change its variables via those accessor methods.


    This page titled 7.3: The Inspector is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.