[Newbies] Adding method to Smallinteger class

Randal L. Schwartz merlyn at stonehenge.com
Fri Apr 23 21:12:20 UTC 2010

>>>>> "Herbert" == Herbert König <herbertkoenig at gmx.net> writes:

Herbert> larger: anInteger
Herbert>   "return the larger of self and anInteger
Herbert>   6 larger: 10
Herbert>   "
Herbert>   anInteger > self ifTrue: [^anInteger] ifFalse: [^self]

or even

  larger: anInteger
  ^self max: anInteger

Code re-use, bay-bee.

And to see what defines "max:", open a "method finder",
type "max:" in the proper window, and you can see the three classes
that define "max:".  The one closest to yours is "Magnitude", which
is anything that has a linear comparability.

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

More information about the Beginners mailing list