I am new to Smalltalk and I am trying to add a new method in the Integer
class present in Smalltalk. The method should go in the 'accessor' protocol. I am using VisualWorks and not finding any option to do that. I have gone through the developers guide still its not clear to me. Can someone please give me screen shots or step wise solution about how to proceed with it?
How to add a new method in Smalltalk source code?
1.3k views Asked by Bosco At
2
There are 2 answers
0
On
If you go into Smalltalk idea, you'll de that classes are objects as well and that you can just say class to compile a new method e.i. add a new method to itself:
Integer compile: 'getSomeVar ^someVar' classified: 'someVar'
_This will add to Integer in someVar
protocol a method called getSomeVar
that will return someVar
instance variable._
But for a general workflow you should use tools provided by Smalltalk environment such as a System Browser mentioned by Aditya Kappagantula
You can find the tab "source" below the 4 partitions [Package, Class, Protocol, Method]. Replace the text in that "source" tab with the source code of your method.
Go to to "edit" option in the Browser menu. Select "Accept" option.
Your new method is added successfully!
Cheers! Aditya.