Skip to content

Instantly share code, notes, and snippets.

@sbrady
Created January 15, 2015 05:03
Show Gist options
  • Save sbrady/9b02c9cfc6609476ccd3 to your computer and use it in GitHub Desktop.
Save sbrady/9b02c9cfc6609476ccd3 to your computer and use it in GitHub Desktop.
Example decorator pattern in Ruby using simple delegate
class Person
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
self.first_name = first_name
self.last_name = last_name
end
end
require 'delegate'
class PersonDecorator < SimpleDelegator
def full_name
"#{first_name} #{last_name}"
end
end
person = Person.new('Sean', 'Brady')
PersonDecorator.new(person).full_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment