Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I lookup which class implements a method in Pharo?

Newbie here, going through "Pharo by Example". The book mentions an example of EllipseMorph new openInWorld result in a call to Morph openInWorld, while EllipseMorph defaultColor is an overridden message: how do I figure this out using the System Browser or something else?

The usual find method way only finds matches in the immediately selected class. Is it possible in general to lookup which class will respond to (say) Foo bar?

Update: Thanks for all the suggestions (Finder, Spotter); the Debugger is the most eye-opening of the tools I've encountered yet!

like image 429
agam Avatar asked Dec 24 '22 14:12

agam


1 Answers

Smalltalk offers lots of tools and browsers that can help you with this. If you already know the name of the message, you can:

  • use spotter (Shift+Enter) to type it in and see all senders and implementers, and select one to browse it.
  • while looking at a method in a browser, click on the small green up/down triangles to the left of the method name indicating implementations up and/or down the hierarchy, respectively, to open a browser on them.
  • select the name of the message (nearly) anywhere and type CMD+M to see the implementors and CMD+N to see the senders.

In this case you could also type EllipseMorph new openInWorld in a playground and select Debug-It from the menu. That will open a debugger with the selection on new. If you click on into, the top line changes to EllipseMorph class(Behavior) new. That indicates that the new from Behavior is used here. If you continue stepping with into (2 times), you'll see it change to EllipseMorph(BorderedMorph) initialize. By just following the trace of messages sent, you can see where everything is implemented.

like image 162
Stephan Eggermont Avatar answered Jan 28 '23 02:01

Stephan Eggermont