Adding method to Character

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding method to Character

tfleig
Hi,

I find myself wanting a Character>>isConsonant method in addition to the existing Character>>isVowel method. It might be defined as

     Character>>isConsonant
         ^ self isLetter & self isVowel not

My question is: what is the best way to do this?

Should I simply add the method to Character? If I do, I guess I must remember to merge my Monticello changes into each new version of Character? Is there some way to bundle this change in my package so I don't forget?

I have created a method in my class MyClass>>characterIsConsonant: aCharacter, but it doesn't read well in the code.

I suppose I could add the method dynamically in my class's initialize method... Not sure how to do that exactly.

Is there another way to do this that I haven't thought of?

Thanks,
TF
Reply | Threaded
Open this post in threaded view
|

Re: Adding method to Character

Stéphane Ducasse

On Nov 11, 2010, at 5:14 PM, Tony Fleig wrote:

> Hi,
>
> I find myself wanting a Character>>isConsonant method in addition to the existing Character>>isVowel method. It might be defined as
>
>      Character>>isConsonant
>          ^ self isLetter & self isVowel not
>
> My question is: what is the best way to do this?
>
> Should I simply add the method to Character? If I do, I guess I must remember to merge my Monticello changes into each new version of Character? Is there some way to bundle this change in my package so I don't forget?

but if you add this method in the character class as a class extension of your package then the addition will be done automatically each time
you load it.

>
> I have created a method in my class MyClass>>characterIsConsonant: aCharacter, but it doesn't read well in the code.
>
> I suppose I could add the method dynamically in my class's initialize method... Not sure how to do that exactly.
>
> Is there another way to do this that I haven't thought of?
>
> Thanks,
> TF


Reply | Threaded
Open this post in threaded view
|

Re: Adding method to Character

tfleig
After a little research...

Great! The last time I used Smalltalk there were no packages. What a useful concept class extensions are.

Is the best way to see a package's extensions to just browse the package (i.e. Ctrl-P in the packages pane of the browser)?

TF

On Nov 11, 2010, at 8:56, Stéphane Ducasse <[hidden email]> wrote:

>
> On Nov 11, 2010, at 5:14 PM, Tony Fleig wrote:
>
>> Hi,
>>
>> I find myself wanting a Character>>isConsonant method in addition to the existing Character>>isVowel method. It might be defined as
>>
>>     Character>>isConsonant
>>         ^ self isLetter & self isVowel not
>>
>> My question is: what is the best way to do this?
>>
>> Should I simply add the method to Character? If I do, I guess I must remember to merge my Monticello changes into each new version of Character? Is there some way to bundle this change in my package so I don't forget?
>
> but if you add this method in the character class as a class extension of your package then the addition will be done automatically each time
> you load it.
>
>>
>> I have created a method in my class MyClass>>characterIsConsonant: aCharacter, but it doesn't read well in the code.
>>
>> I suppose I could add the method dynamically in my class's initialize method... Not sure how to do that exactly.
>>
>> Is there another way to do this that I haven't thought of?
>>
>> Thanks,
>> TF
>
>