[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Easiest way to add new methods to kernel classes (from

From: Rick Flower
Subject: [Help-smalltalk] Easiest way to add new methods to kernel classes (from within a script)?
Date: Thu, 25 Feb 2010 14:14:23 -0800
User-agent: RoundCube Webmail/0.2.1


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]
                        [last := (self findFirst: [ :char | char isSeparator] 
first) - 1.
                        last < 0 ifTrue: [last := self size].
                        collection add: (self copyFrom: first to: last)].
        ^collection asArray
! !


reply via email to

[Prev in Thread] Current Thread [Next in Thread]