Ruby idiomatic way to return a boolean -
is there more idiomatic way me return boolean in #survey_completed? how did things in c#, , have felt last ternary clause return false redundant, perhaps ruby has better way of doing this?
this how code looks like:
def survey_completed? self.survey_completed_at ? true: false end def survey_completed_at # seeing survey submitted or nothing, time last response persisted # when survey completed last_response = self.responses.last if last_response last_response.created_at end end
you can use double negation:
def survey_completed? !!survey_completed_at end
Comments
Post a Comment