Skip to content

Instantly share code, notes, and snippets.

@rodloboz
Created January 15, 2020 03:43
Show Gist options
  • Save rodloboz/3edcb6a5ca795c24165283da963d24be to your computer and use it in GitHub Desktop.
Save rodloboz/3edcb6a5ca795c24165283da963d24be to your computer and use it in GitHub Desktop.
Presenters & Decorators
class UserProfilePresenter
def initialize(user)
@user = user
end
def full_name
"#{@user.first_name} #{@user.last_name}"
end
def short_summary
@user.summary.truncate(50)
end
def creation_date
"Created at #{@user.created_at.strftime('%Y/%m/%d')}"
end
end
class UserProfileDecorator < SimpleDelegator
def model
__getobj__
end
def name
"#{model.first_name} #{model.last_name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment