Reputation: 2002
I know that for an instance variable all I have to do is put it inside the initialise method in the instance side and assign it a default value. But how I do this for class variable ? I tried to create an initialise method at class side but it did not give my variable a default value so I had to do this in one of my methods
pythonString ifNil:[pythonString := '']
But I don't like this approach.
I also found this for squeak , http://forum.world.st/Howto-initialize-class-variables-td1667813.html again I don't like this approach either. Is there a proper way of doing this. In Python it was fairly simple case of assignment why is it so cryptic for Pharo ?
Upvotes: 4
Views: 2096
Reputation: 13386
First of all I hope that you are talking about instance variable of a class object (not a thing that you define on instance side as "class variable").
initialize
is working, but it's being run upon instance creation. And instance (a class object) exists already when you define initialize
method.
So when you define your class for the first time, you should run it by yourself e.g. YourClass initialize
, bun later each time you load your class into system it should be initialised.
Upvotes: 5