This is my function
def rating(array)
sum_count = array.values.inject(0) { |sum_count,value| sum_count + value }
run_count = 0
array.each do |tag,count|
run_count += count
cum_distn = run_count/sum_count
logger.debug "cum_distn is #{cum_distn.to_f}; run_count is #{run_count.to_f}; sum_count is #{sum_count}"
if cum_distn < 0.25
...
elsif cum_distn < 0.5
...
else
...
end
end
end
For 2 objects in my array with counts of 1 each, my logger is showing this:
cum_distn is 0.0; run_count is 1.0; sum_count is 2
cum_distn is 1.0; run_count is 2.0; sum_count is 2
It seems that the value of cum_distn is only updating once one loop is complete whilst I intend for it to update immediately before the if function opens. I have two questions:
(a) Why is this happening (as I can't see any logical explanation)?
(b) How can I rectify this to do what I want?