Method in 'collect' 
Author Message
 Method in 'collect'

Hi!

I've got some trouble and wounder if some one can help me.

I've got an Array with my 'Bank'-objects in. And I'm doin a collect
"thing" on it.. like:

SavingsArray collect [:each|each custName.].

custName is a method in my Bank class that returns the customers name. The
problem is that I can't reach the method 'custName' in the Bank-class in
the array
puuhhhhh...

The compiler answers with 'Message not understood'

HEEELp ;)

Thanx

/adam



Wed, 18 Jun 1902 08:00:00 GMT  
 Method in 'collect'
On Wed, 30 Sep 1998 16:48:55 +1000, Adam Bervenstahl

Quote:

>Hi!

>I've got some trouble and wounder if some one can help me.

>I've got an Array with my 'Bank'-objects in. And I'm doin a collect
>"thing" on it.. like:

>SavingsArray collect [:each|each custName.].

>custName is a method in my Bank class that returns the customers name. The
>problem is that I can't reach the method 'custName' in the Bank-class in
>the array
>puuhhhhh...

>The compiler answers with 'Message not understood'

You need to give us a bit more information, when you get the 'Message
not understood' error, you should actually see something like 'foo
does not understand #custName'. It is my guess that your array doesn't
contain a Bank in every index position. The #collect: method on an
array iterates through each index position and sends #custName to the
object referenced by it. This means that if any of the index positions
contains nil or something that is not a Bank then you will have
problems.

To debug this, you should place a self halt just before the #collect:
statement and inspect the contents of SavingsArray to make sure it
contains instances of Bank.

Good luck



Wed, 18 Jun 1902 08:00:00 GMT  
 Method in 'collect'

Quote:
> I've got an Array with my 'Bank'-objects in. And I'm doin a collect
> "thing" on it.. like:

> SavingsArray collect [:each|each custName.].

> custName is a method in my Bank class that returns the customers name.
The
> problem is that I can't reach the method 'custName' in the Bank-class in
> the array. The compiler answers with 'Message not understood'

Are you certain it is the custName message that is not understood? collect
should
have a colon after it:

SavingsArray collect: [:each|each custName.].



Wed, 18 Jun 1902 08:00:00 GMT  
 Method in 'collect'
On 30 Sep 1998 13:58:21 GMT, "Malcolm Macgregor"

Quote:

>> I've got an Array with my 'Bank'-objects in. And I'm doin a collect
>> "thing" on it.. like:

>> SavingsArray collect [:each|each custName.].

>> custName is a method in my Bank class that returns the customers name.
>The
>> problem is that I can't reach the method 'custName' in the Bank-class in
>> the array. The compiler answers with 'Message not understood'
>Are you certain it is the custName message that is not understood? collect
>should
>have a colon after it:

>SavingsArray collect: [:each|each custName.].

Good catch, assuming he didn't just typo when putting it into the
post.

I have not seen the orignal post so there may be a rational but I'm
curious about using an Array.  Why not use an OrderedCollection?
Especially with something like Savings and Banks.  Unless there is
some reason that there are only allowed to be certain numbers of Banks
per SavingsArray.

Anyway, my guess would be that not all the elements in the array are
Banks.  I would feel that some may still be nil and those are giving
him that #doesNotUnderstand:

If that is the case than a quick fix would be

        ^(SavingsArray reject: [: each | each isNil)
                collect: [: bank | bank custName]

Take care,

Jay O'Connor

http://www.roadrunner.com/~joconnor

"God himself plays on the bass strings first, when he tunes the soul"



Wed, 18 Jun 1902 08:00:00 GMT  
 Method in 'collect'

Quote:

>Hi!

>I've got some trouble and wounder if some one can help me.

>I've got an Array with my 'Bank'-objects in. And I'm doin a collect
>"thing" on it.. like:

>SavingsArray collect [:each|each custName.].

>custName is a method in my Bank class that returns the customers name. The
>problem is that I can't reach the method 'custName' in the Bank-class in
>the array
>puuhhhhh...

If every object in the collection is an instance of the class Bank,
make sure that the custName method is an instance method and not a
class method. Others have provided alternative reasons to your
problem, and I am sure somebody has guessed it right by now:-)

Quote:

>The compiler answers with 'Message not understood'

>HEEELp ;)

>Thanx

>/adam

Adonis Ioannou


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. vrml 2.0 activeX control that allows java methods to access container's methods

2. Recursive methods with :around's and call-next-method results

3. A garbage collector which won't collect

4. objects that won't be garbage collected (VW 2.0)

5. I'm collecting a list of industrial Eiffel users

6. Why collected languages don't need a free operation

7. LabVIEW's equivalent to Excel's GoalSeek method

8. Method type 'abstract'

9. 'bind' functions into methods

10. Invoking a subclass's method on its superclass's instance

11. methods in 'C' - persistent data structures

12. 'capwords' is not a string method

 

 
Powered by phpBB® Forum Software