[Pharo-dev] reflection examples

Torsten Bergmann astares at gmx.de
Tue Aug 20 17:08:14 EDT 2013

Ask someone from another language how they count their
tests classes. In Smalltalk you can easily:

 TestCase allSubclasses size

or write other nice statistics scripts about your programs. 

Reflection can be used to find an appropriate selector when you
know the input and the result. I'm sure you know that features available in 
the finder tool:  3. 4. 7.

or according examples from the finder tool like:

  MethodFinder methodFor: #( (4 3) 7  (0 5) 5  (5 5) 10).

Maybe the PragmaCollector is also a nice example: just define a method


 and then:

   (PragmaCollector filter: [:pragma | #todo = pragma keyword]) reset collected

Also have a look at "Teachable" from config browser. It's not directly related
to reflection but shows how easy it is to use #doesNotUnderstand and write
mocks. One can do other nice tricks - like implement a getter automagically when it 
is not there, ... 

Beware - you already know the "true become: false" trick ;)

More information about the Pharo-dev mailing list