Greetings,
I have an instance method called ‘initialize’ that defines instance variables.
I want it to run whenever a new instance is created. How do I accomplish that?
I tried to add a class method ‘new’ that contained ^(super new) initialize. But it warned me about adding the message saying it would have serious effects.
So where do I put it?
Sincerely,
Joe.
Hi Joe,
Excellent question. Try this.
Object new.
Highlight it and do debug it. Click "Into" to go into the #new method.
Notice the implementation of #new.
You should be able to see there that #initialize is called automatically.
Also for extra points notice what class new is implemented on. What method should you call to skip initialize?
All the best,
Ron Teitelbaum
-----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners- bounces@lists.squeakfoundation.org] On Behalf Of Joseph Alotta Sent: Tuesday, May 10, 2016 2:07 PM To: beginners@lists.squeakfoundation.org Subject: [Newbies] new and initialize
Greetings,
I have an instance method called ‘initialize’ that defines instance variables.
I want it to run whenever a new instance is created. How do I accomplish that?
I tried to add a class method ‘new’ that contained ^(super new) initialize. But it warned me about adding the message saying it would have serious effects.
So where do I put it?
Sincerely,
Joe.
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] ml-node+s1294792n4894228h17@n4.nabble.com wrote:
Hi Joe,
Excellent question. Try this.
Object new.
Highlight it and do debug it. Click "Into" to go into the #new method.
Notice the implementation of #new.
You should be able to see there that #initialize is called automatically.
Also for extra points notice what class new is implemented on.
Behavior
What method should you call to skip initialize?
basicNew
More questions: why isn’t there a command key for debug it? why isn’t my initialize method not running or running without setting variables?
Thank you.
Sincerely,
Joe.
-- View this message in context: http://forum.world.st/new-and-initialize-tp4894227p4894237.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
On Wed, May 11, 2016 at 3:37 AM, Joseph Alotta joseph.alotta@gmail.com wrote:
On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
Hi Joe,
Excellent question. Try this.
Object new.
Highlight it and do debug it. Click "Into" to go into the #new method.
Notice the implementation of #new.
You should be able to see there that #initialize is called automatically.
Also for extra points notice what class new is implemented on.
Behavior
What method should you call to skip initialize?
basicNew
More questions: why isn’t my initialize method not running or running without setting variables?
Is your initialize method on the class-side or the instance-side ? At the very very start of using Squeak this would catch me up. It soon became instinctive to notice which side I was working on.
cheers -ben
From: Joseph Alotta Sent: Tuesday, May 10, 2016 3:38 PM
On May 10, 2016, at 12:45 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
Hi Joe,
Excellent question. Try this.
Object new.
Highlight it and do debug it. Click "Into" to go into the #new method.
Notice the implementation of #new.
You should be able to see there that #initialize is called automatically.
Also for extra points notice what class new is implemented on.
Behavior
[Ron Teitelbaum] Exactly!
What method should you call to skip initialize?
basicNew
[Ron Teitelbaum] Excellent!
More questions: why isn’t there a command key for debug it?
[Ron Teitelbaum] No clue.
why isn’t my initialize method not running or running without setting variables?
[Ron Teitelbaum] put a halt in your method and run it. See if the initialize is being called at all. If it is then check the content of your method for errors. If not then your initialize method is spelled wrong, is not on the instance side, or there is a new method implemented in your class or a superclass that is bypassing the default implementation of #new which is a bad thing. The system gives you a warning to let you know that!! J
All the best,
Ron
Thank you.
Sincerely,
Joe.
_____
View this message in context: Re: new and initialize http://forum.world.st/new-and-initialize-tp4894227p4894237.html Sent from the Squeak - Beginners mailing list archive http://forum.world.st/Squeak-Beginners-f107673.html at Nabble.com.
Hi.
On Tue, May 10, 2016 at 12:37 PM, Joseph Alotta joseph.alotta@gmail.com wrote: <snip>
More questions: why isn’t there a command key for debug it?
I just learned this today - we do have a command key (well, command key sequence) for debug it:
Shift+Cmd+D to "Debug it"
-cbc
Sorry, it doesn’t work on the Mac. The window gets black and then redraws. I think maybe it means “refresh”.
Sincerely,
JOe.
On May 11, 2016, at 5:07 PM, cbc [via Smalltalk] ml-node+s1294792n4894371h50@n4.nabble.com wrote:
Hi.
On Tue, May 10, 2016 at 12:37 PM, Joseph Alotta <[hidden email]> wrote:
<snip> More questions: why isn’t there a command key for debug it?
I just learned this today - we do have a command key (well, command key sequence) for debug it:
Shift+Cmd+D to "Debug it"
-cbc
Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners
If you reply to this email, your message will be added to the discussion below: http://forum.world.st/new-and-initialize-tp4894227p4894371.html To start a new topic under Squeak - Beginners, email ml-node+s1294792n107673h12@n4.nabble.com To unsubscribe from Squeak - Beginners, click here. NAML
-- View this message in context: http://forum.world.st/new-and-initialize-tp4894227p4894377.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
On 12.05.2016, at 01:50, Joseph Alotta joseph.alotta@gmail.com wrote:
Sorry, it doesn’t work on the Mac. The window gets black and then redraws. I think maybe it means “refresh”.
Sincerely,
JOe.
Joe, which version of Squeak are you using? 5.0 does not yet have this shortcut but the current development version (trunk / 5.1alpha) does.
Best regards -Tobias
beginners@lists.squeakfoundation.org