How do I make this Ruby method more 'ruby-esque' - i.e. DRY and sleek?
-
28-10-2019 - |
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.
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
OTHER TIPS
Exactly one line :)
def first_login?
sign_in_count <= 20
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow