これが私の機能です
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
それぞれカウントが1の配列内の2つのオブジェクトの場合、ロガーは次のように表示します。
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
cum_distnの値は、1つのループが完了したときにのみ更新されているようですが、if関数が開く直前に更新する予定です。2つの質問があります:
(a)なぜこれが起こっているのですか(論理的な説明が見当たらないため)?
(b)これを修正して自分のやりたいことを行うにはどうすればよいですか?