How do I make this Ruby method more 'ruby-esque' - i.e. DRY and sleek?

217 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER
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

0
On

Exactly one line :)

def first_login?
   sign_in_count <= 20
end