Last updated at 8:38 am UTC on 18 September 2019
The Method Finder is a development tool to help find Method Statements existing in the Squeak image. There are two ways to use the Method Finder,
Here is a short video illustrating both of them.
- by keyword or part of it and
- by example.
Finding methods by keyword
Many times the question "how do I do this?" can be answered using the Method Finder:
- Choose "open..." from the World menu, then choose "method finder".
- Type a keyword you are interested in in the upper left-hand pane, and accept (cmd-s).
- In the lower left-hand pane will appear a list of selectors containing your keyword, and selecting one of these will bring up a list of all implementers in the right-hand pane.
- Selecting one of those will bring up a browser on that particular method.
Finding methods by example
But the coolest and most unusual thing about the Method Finder is using it to find methods by example. In other words, you feed the input and output objects to the method finder, and it magically looks up all of the methods which will satisfy the transformation. For example, enter:
3. 4. 7
into the top left pane of the method finder, and hit return. (3 and 4 are the inputs, the last item 7 is the output.) It will figure out that the "+" message satisfies this (because 3 + 4 -> 7), and it also finds a couple of other methods.
Let's say you want to find out what method returns the last element of a collection. Simply enter an example collection, a period, and then the expected answer (which would be the last item), like this:
#('one' 'two' 'three'). 'three'
The Method Finder shows these results:
#('one' 'two' 'three') last –> 'three'
#('one' 'two' 'three') median –> 'three'
#('one' 'two' 'three') third –> 'three'
This means that the #last message will work, and so will the #median and #third messages. (We can confirm this by entering #('one' 'two' 'three') last into a Workspace, highlighting it and doing a 'print it', and it will indeed return 'three'.)
Anyway, the #last message sounds like the one we want. It also makes sense that it found #third. #median might be a surprise, but apparently it found that one by sorting the elements in the collection (alphabetically) and taking the middle element.
Here are some other examples to type into the method finder, to get a feel for its possibilities:
'abc'. 'def'. 'abcdef' "How do I concatenate two strings?"
Answer: With #, 'abc','def','abcdef'
' trim my spaces '. 'trim my spaces' "How do I trim spaces from a string?"
Answer: With #withBlanksCondensed or #withBlanksTrimmed ' trim my spaces ' withBlanksTrimmed.
4@4. 2@2 corner: 6@6. true "How do I determine if a point is inside a rectangle?"
The SqueakNews monthly e-zine includes an essay on the method finder (in the July 2001 issue) by Ted Kaehler. It goes into some detail on how the Method Finder was conceived and implemented.