我正在从“Programming ruby 1.9”中学习 ruby。我正在学习使用 ruby-debug,所以我可以理解下面发生的事情。我使用 rubymine,因为它集成了 ruby-debug19 或类似的东西(它说我没有 gem 并安装它)。这是问题,我能够单步执行代码并探索变量和堆栈。但是,当它到达 a 时for i in 0...5
,调试器会说
堆栈帧不可用
我知道 ruby 很少使用 for 循环,但我仍然想知道是否通过 for 循环进行调试。
代码:
raw_text = %{
The problem breaks down into two parts. First, given some text as a
string, return a list of words. That sounds like an array. Then, build a
count for each distinct word. That sounds like a use for a hash---we can
index it with the word and use the corresponding entry to keep a count.}
word_list = words_from_string(raw_text)
counts = count_frequency(word_list)
sorted = counts.sort_by {|word, count| count}
top_five = sorted.last(5)
for i in 0...5 # (this is ugly code--read on
word = top_five[i][0] # for a better version)
count = top_five[i][1]
puts "#{word}: #{count}"
end