#<>
#caseOf:otherwise:が簡単すぎたので,ちょっと捻ってRuby風のcaseを。
!Object methodsFor: 'rubylike-case'! <> cases cases do: [:a| a key =? self and: [ | v | ^((v := a value) isKindOf: BlockClosure) ifTrue: [ v value ] ifFalse: [ v ] ] ]. ^nil! case: cases ^self <> cases! case: cases else: elseBlock ^self <> cases ifNil: elseBlock! =? o ^self = o! ! Object subclass: #Any instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: '?'! !Any class methodsFor: 'rubylike-case'! =? o ^true! !BlockClosure methodsFor: 'rubylike-case'! =? o ^self value = o! !Class methodsFor: 'rubylike-case'! =? o ^o isKindOf: self! !CharacterArray methodsFor: 'rubylike-case'! =? o ^self match: o! !Collection methodsFor: 'rubylike-case'! =? o ^self includes: o! !
例えばこれを訳すと
Age <> { (0 to: 2) -> 'baby'. (3 to: 6) -> 'little child'. (7 to: 12) -> 'child'. (13 to: 18) -> 'youth'. Any -> 'adult'. }
こうなる。