Say you have two classes, LuckyClass1
a subclass of Object
and LuckyClass2
subclass of LuckyClass1
. And let's say your name is LuckyName
. And let's say you want to put your code into the package Lucky-Package1
.
Object subclass: #LuckyClass1
LuckyClass1 subclass: #LuckyClass2
Class LuckyClass1
with an instance side method luckyInstanceSideMethod1
, a class side method luckyClassSideMethod1
and instance side variable luckyInstanceSideVariable1
and class side variable LuckyClassSideVariable1
.
Similarly class LuckyClass2
with an instance side method luckyInstanceSideMethod1
, a class side method luckyClassSideMethod1
and an additional instance side variable luckyInstanceSideVariable2
and class side variable LuckyClassSideVariable2
.
Method references would look like this
LuckyClass1>>#luckyInstanceSideMethod1
LuckyClass1 class>>#luckyClassSideMethod1
LuckyClass2>>#luckyInstanceSideMethod1
LuckyClass2 class>>#luckyClassSideMethod1
On Linux/Mac OS X, do
vi Lucky-Package1-unix.st
to put in a file named Lucky-Package1-unix.st
something like
Object subclass: #LuckyClass1
instanceVariableNames: 'luckyInstanceSideVariable1'
classVariableNames: 'LuckyClassSideVariable1'
poolDictionaries: ''
category: 'Lucky-Package1'!
!LuckyClass1 methodsFor: 'lucky instance side protocol 1' stamp: 'LuckyName 6/8/2016 17:05'!
luckyInstanceSideMethod1
^ luckyInstanceSideVariable1 := 'lucky instance side'
! !
!LuckyClass1 class methodsFor: 'lucky class side protocol 1' stamp: 'LuckyName 6/8/2016 17:06'!
luckyClassSideMethod1
^ LuckyClassSideVariable1 := 'lucky class side'
! !
LuckyClass1 subclass: #LuckyClass2
instanceVariableNames: 'luckyInstanceSideVariable2'
classVariableNames: 'LuckyClassSideVariable2'
poolDictionaries: ''
category: 'Lucky-Package1'!
!LuckyClass2 methodsFor: 'lucky instance side protocol 1' stamp: 'LuckyName 6/8/2016 17:15'!
luckyInstanceSideMethod1
^ super luckyInstanceSideMethod1, ' subclass'
! !
!LuckyClass2 class methodsFor: 'lucky class side protocol 1' stamp: 'LuckyName 6/8/2016 17:17'!
luckyClassSideMethod1
^ super luckyClassSideMethod1, ' subclass'
! !
In fact, you can cut & paste the preceding block.
Then convert linefeeds to carriage returns or else Pharo will complain. This is important. If you are on Linux/Mac OS X you can use the following
cat Lucky-Package1-unix.st | tr \\n \\r > Lucky-Package1-pharo.st
On Windows I would still use bash, vi, cat, tr from git-scm https://git-scm.com/download/win
Then file in Lucky-Package1-pharo.st
. It should appear in the Lucky-Package1
package in System Browser.