Add to a collection
Ned Konz
ned at bike-nomad.com
Mon Feb 3 01:02:41 UTC 2003
On Sunday 02 February 2003 04:54 pm, Janet Abdul-Karim wrote:
> I created a subclass to ordered collections. I am trying to add
> objects to the new class and then print it to make sure they are in
> there. I add one object it prints but when I add another object
> and print it only prints the first object i added
>
> sample code to add to list.
>
> account: aAccount
> "Add an account to the portfolio"
>
> self isNil ifTrue:[self add: aAccount]
> ifFalse:[ self addLast: aAccount].
>
>
>
> code to print list.
>
> ccounts
> "Returns the accounts for the portfolio"
>
> self do:[:element|^element number].
If you really want to return the accounts you should do something
like:
ccounts
^self collect: [ :element | element number ]
which will return a collection of element numbers.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|