【发布时间】:2015-12-06 14:27:06
【问题描述】:
def exit
@result = 0
@correct_answer = Question.pluck(:correct_answer).first
@selected_answer = Question.pluck(:selected_answer).first
@id = Question.pluck(:id)
@questions = Question.all
#binding.pry
@questions.each do |i|
if @correct_answer == @selected_answer
@result += 1
else
@result -= 1
end
end
end
我在实现 .each 循环后使用此代码,我的 if 条件未执行它总是执行块
我该如何解决这个问题
【问题讨论】:
-
除非你明白你在做什么,否则不要命名一个方法
exit。由于exit已经是一个现有的方法名称,因此您将创建一个令人困惑的脚本。
标签: ruby ruby-on-rails-4 each