[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Easiest way to add new methods to kernel classes (f
From: |
Rick Flower |
Subject: |
Re: [Help-smalltalk] Easiest way to add new methods to kernel classes (from within a script)? |
Date: |
Thu, 25 Feb 2010 15:12:19 -0800 |
User-agent: |
RoundCube Webmail/0.2.1 |
On Thu, 25 Feb 2010 14:14:23 -0800, Rick Flower <address@hidden>
wrote:
> Paolo,
>
> I'd like to add >>asArrayOfSubstrings (found in the Smalltalk
> by Example book) into the CharacterArray class but would like
> it to remain within my script so that I don't modify the kernel
> files directly.. What's the best way to do that? I tried adding
> it to the top of my script file like shown below but GST wasn't
> too happy about it.. Do I need to convert over to the new style
> syntax to do this sort of thing or something else?
>
> #!/usr/local/bin/gst -f
>
> ArrayedCollection subclass: #CharacterArray
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Collections-Text'!
>
> asArrayOfSubstrings [
> <category: 'converting'>
> | first last collection |
>
> collection := OrderedCollection new.
> last := 0.
> [first := self findFirst: [ :char | char isSeparator not] startingAt:
> last + 1. first ~= 0]
> whileTrue:
> [last := (self findFirst: [ :char | char isSeparator]
> startingAt:
> first) - 1.
> last < 0 ifTrue: [last := self size].
> collection add: (self copyFrom: first to: last)].
> ^collection asArray
> ! !
Ok..I converted the above code into the new format (along
with the rest of my script) and the code above looks
something like :
CharacterArray extend [
asArrayOfSubstrings [
<category: 'converting'>
| first last collection |
collection := OrderedCollection new.
last := 0.
[first := self findFirst: [ :char | char isSeparator not] startingAt:
last + 1. first ~= 0]
whileTrue:
[last := (self findFirst: [ :char | char isSeparator]
startingAt:
first) - 1.
last < 0 ifTrue: [last := self size].
collection add: (self copyFrom: first to: last)].
^collection asArray
]
But that causes problems with any class definitions below this code.. with
errors like : invalid class body element.. I think I'm close..