有没有更惯用的方法来返回布尔值#survey_completed?
?这就是我在 C# 中做事的方式,我一直觉得最后一个返回的三元子句false
是多余的,所以也许 Ruby 有更好的方法来做到这一点?
这就是我的代码当前的样子:
def survey_completed?
self.survey_completed_at ? true: false
end
def survey_completed_at
# Seeing as the survey is submitted all or nothing, the time the last response is persisted
# is when the survey is completed
last_response = self.responses.last
if last_response
last_response.created_at
end
end