This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Super weirdness
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
I always say that the two strangest things in the Smalltalk syntax are blocks (by far the strangest) and super. Here are some things that will test your intuitions about super. What happens in each case?
Case 1:
someMethod
[:x | x foo: 'john'] value: super
Does it call foo: in the subclass or the superclass?
Case 2:
someMethod
^super
SomeClass new someMethod foo: 'peter'
Is foo: the subclass or superclass implementation?
Case 3:
someMethod
super
bar;
foo: 'Peter'
Which foo: is called?
In all these cases, would you have been able to tell if you hadn't tried it? (Hint - try it in other Smalltalks - the answers may be different.)