Reputation: 590
I was going through (using Squeak) the Discovering Better Code: Bowling for Smalltalk Series by Ron Jeffries and I can't get pass through the third article.
A new class (called Frame) is being created which takes an array as an argument in the constructor.
Frame class>>new: anArray
^self new setRolls: anArray
Frame>>setRolls: anArray
rolls := anArray
When I try to run this in a simple test:
testFrame
| frame rolls |
rolls := Array with: 5 with: 4.
frame := Frame new: rolls.
I get the following error:
alt text http://files.getdropbox.com/u/120566/junk/error.png
How should I modify the #new message to be able to initialize Frame object with an array?
Upvotes: 1
Views: 711
Reputation: 44056
You really don't want to override new:
here. new:
is traditionally reserved for "Create an item of this integer size", and it doesn't surprise me that it's blowing up on you.
A more traditional name for the kind of constructor you want is fromArray:
, or perhaps even fromCollection:
which would probably have worked as you wished.
Upvotes: 0
Reputation: 2589
I guess you failed adding the method new: correctly to Frame class. Are you sure you put it on the class side (Frame class) and not on the instance side (Frame)? To do it, click on the 'class' button, before adding your method new:.
Upvotes: 3