Created
December 8, 2008 18:28
-
-
Save mkhl/33552 to your computer and use it in GitHub Desktop.
Smalltalk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Extensions for making writing classes with accessors a bit less verbose" | |
ClassDescription extend [ | |
accessors: aString [ | |
self readers: aString. | |
self writers: aString. | |
] | |
readers: aString [ | |
aString substrings do: [:ivar | | |
(self allInstVarNames includes: ivar asSymbol) | |
ifFalse: [ self addInstVarName: ivar ]. | |
self createGetMethod: ivar. | |
] | |
] | |
writers: aString [ | |
aString substrings do: [:ivar | | |
(self allInstVarNames includes: ivar asSymbol) | |
ifFalse: [ self addInstVarName: ivar ]. | |
self createSetMethod: ivar. | |
] | |
] | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"This is a small method that illustrates every part of Smalltalk method syntax except primitives" | |
|y| | |
true & false not & (nil isNil) ifFalse: [self halt]. | |
y := self size + super size. | |
#($a #a 'a' 1 1.0) | |
do: [:each | Transcript | |
show: (each class name); | |
show: (each printString); | |
show: ' ']. | |
^ x < y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment