Last active
December 22, 2015 15:19
-
-
Save kossnocorp/6491700 to your computer and use it in GitHub Desktop.
How to refactor methods like this one?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def activity_status | |
if currently_working? | |
'working' | |
elsif worked_recently? | |
'active' | |
elsif has_activity? | |
'inactive' | |
elsif signed_in_at_least_once? | |
'no_activity' | |
else | |
'never_sign_in' | |
end | |
end |
Author
kossnocorp
commented
Sep 9, 2013
def activity_status
return 'working' if currently_working?
return 'active' if worked_recently?
return 'inactive' if has_activity?
return 'no_activity' if signed_in_at_least_once?
'never_sign_in'
end
def activity_status
case
when currently_working? then 'working'
when worked_recently? then 'active'
when has_activity? then 'inactive'
when signed_in_at_least_once? then 'no_activity'
else 'never_sign_in'
end
end
Although above solutions are good, however i add new style for variability:
def activity_status
currently_working? && 'working' or
worked_recently? && 'active' or
has_activity? && 'inactive' or
signed_in_at_least_once? &&'no_activity' or
'never_sign_in'
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment