Hal E. Fulton
7/30/2006 4:14:00 AM
Ben Atkin wrote:
> Instance variables are prefixed with an @ symbol. I would guess that you
> want countExch to be an instance variable. Also, I think the declaration
> might need to go in the initialize method.
>
> Someone who is more experienced w/ Ruby please give a more accurate and/or
> complete answer.
Basically right.
I'll point out that "camelCase" is not usually our style. We're more
likely to say "count_exch" -- of course, Ruby itself doesn't care.
I'm not sure what the code is doing really. But these statements
are very confusing at the least:
@countExch[eachSymbolObj.exchange]=@countExch[eachSymbolObj.exchange]+=1
@countExch[eachSymbolObj.exchange]=startCounter+=1;
The first is the same as saying:
@countExch[eachSymbolObj.exchange] += 1
if I'm not mistaken. And the second is more clearly represented as
startCounter += 1
@countExch[eachSymbolObj.exchange] = startCounter
But maybe you want to use each_with_index instead of each, and you
won't have to manually keep a counter.
What exactly is this all about?
Hal