Friday, 16 August 2013

Ruby idiomatic way to return a boolean

Ruby idiomatic way to return a boolean

Is there a more idiomatic way for me to return a boolean in
#survey_completed? This is how I did things in C#, and I have always felt
that the last ternary clause to return false was redundant, so perhaps
Ruby has a better way of doing this?
This is how what my code currently looks like:
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

No comments:

Post a Comment