**已关闭。**此问题需要debugging details。它目前不接受回答。
编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
上个月关门了。
Improve this question
我有一个Ruby 3.2.2的代码bug,这让我很困惑。使用byebug单步执行代码,执行将从第70行跳到第100行--发生这种情况确实令人困惑。
我在这里包含了相关的代码片段,带有行号,参数中aline的值为“2022 Outdoor Journal”:
61 def test_for_nonentry_lines( aline )
62
63 if 'JANUARY FEBRUARY MARCH APRIL MAY JUNE JULY AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER'.include? aline
64 # If a month is detected, it means processing is between trip entries,
65 # so set global IN_ENTRY to false:
66 $IN_ENTRY = false
67 return true
68 elsif aline.include?('Outdoor Journal')
69 $IN_ENTRY = false
70 return true
71 elsif aline.include?('——————')
72 $IN_ENTRY = false
73 return true
74 elsif aline =~ /^\n$/ and not $IN_ENTRY
75 # If this is a blank line but we're not writing a trip entry,
76 # then this is a nonentry line:
77 return true
78 else
79 return false
80 end
81 end
82
83 # ----------------------------------------------
84 # is_start_of_entry
85 #
86 # tests current line as to whether is the start
87 # of a new journal entry. returns boolean.
88 # ----------------------------------------------
89 def is_start_of_entry( aline )
90
91 # use a regexp to test if the passed in current line is start of a journal entry,
92 # the pattern here is either the string "(pics)"
93 # AND a date pattern like 1/15/22 or 1/5/22:
94 # ELSE IF
95 # the pattern matches this pattern: a blank line followed
96 # by (some chars a comma)*n, a date, then a comma
97
98 # A line is the start of the new entry if:
99 # - the line has a date & contains the string "(pics)"
100 if aline =~ /\d?\d\/\d?\d\/\d\d/ and aline =~ /(pics)/
101 return true
代码执行应该在第70行“返回true”。我正在使用byebug来单步执行代码,当它执行第70行时,程序跳转到第100行..
如果需要,可以提供整个程序。
提前感谢任何帮助…
2条答案
按热度按时间blmhpbnm1#
以下是其中一种方式:
如果你跳到了你没有想到的地方,看看回溯
bt
,你也可以去up
看看:另外,在byebug中没有颜色,使用
debugger
代替,默认情况下应该已经有了 https://github.com/ruby/debug。shyt4zoc2#
我认为问题是由case语句中使用的=操作符引起的。虽然我不能证明这一点,但当我用if/then语句替换case语句时,代码就开始工作了。