How do I make this Ruby method more 'ruby-esque' - i.e. DRY and sleek?
-
16-04-2021 - |
Question
Consider:
def first_login?
if (self.sign_in_count <= 20)
return true
else
return false
end
end
It would be nice if I could just have it be 1 line of code...if possible.
La solution
def first_login?
self.sign_in_count <= 20
end
Your comparison already returns boolean value
You don't need self
as well because methods are invoked on self implicitly
Autres conseils
Exactly one line :)
def first_login?
sign_in_count <= 20
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow