else
countExch[eachSymbolObj.exchange]=startCounter+=1;
end
}
puts countExch.to_s
end
end
I get the folliwng error.
1) Error:
Test_ReportBuilder#test_Case1:
NameError: undefined local variable or method `countExch' for
#<ReportBuilder:0xd29af88>
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.
Ben
class ReportBuilder
def initialize
@countExch=Hash.new
end
def getStats(symbolObjColl)
startCounter=0
#### add a loop to count thro symbolcollection.
symbolObjColl.each{|eachSymbolObj|
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: