Questions about smalltalk/x and its class library

Adding a method to class

Postby smalltalker89 » 3. Jan 2010, 06:26


how can i add a simple method to a simple class in smalltalk x
by using just code without browser .

for example:
why this is not good?

(i tried to do it by the tutorial of smalltalk x.. )

Object subclass: #Tokenizer
instanceVariableNames: 'name'
classVariableNames: ''
poolDictionaries: ''
category: 'MakingSmalltalk-Article2'

name:= newName

t:=Tokenizer new.
t setName:'Miller'.

it doesn't know the method
i want it to connect setName with the class Tokenizer

Posts: 3
Joined: 27. Nov 2009, 14:17

Re: Adding a method to class

Postby jan_vrany » 3. Jan 2010, 11:12

There are several ways how to add a method into a class. Probably the easiest is to use
#compile:classified:, like (assuming that class Tokenizer already exists)

Code: Select all
    compile:'setName: aString
name := aString'
    classified: 'accessing'

The first argument is the source code (as string) of the new method, the second one is method category.
Posts: 28
Joined: 10. Dec 2008, 12:37

Return to Programming Help

Users browsing this forum: No registered users and 1 guest

Design by GB