Skip to content

Instantly share code, notes, and snippets.

@kossnocorp
Last active December 22, 2015 15:19
Show Gist options
  • Save kossnocorp/6491700 to your computer and use it in GitHub Desktop.
Save kossnocorp/6491700 to your computer and use it in GitHub Desktop.
How to refactor methods like this one?
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
@dmitryn
Copy link

dmitryn commented Sep 9, 2013

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