Skip to content

Instantly share code, notes, and snippets.

@dreamr
Last active August 29, 2015 14:03
Show Gist options
  • Save dreamr/043946e7d8fd94324e4f to your computer and use it in GitHub Desktop.
Save dreamr/043946e7d8fd94324e4f to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
def display_name
full_name || email_designator || "I haz no name nor email!"
end
def email_designator
return nil if email.blank?
@email_designator = email.split("@")[0]
end
def full_name
@full_name = "#{first_name} #{last_name}"
@full_name unless @full_name.blank?
end
end
@rhamlin
Copy link

rhamlin commented Jun 30, 2014

Much nicer solution.

@sampritipanda
Copy link

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment