Skip to content

Instantly share code, notes, and snippets.

@mgreenly
Created November 27, 2011 16:39
Show Gist options
  • Save mgreenly/1397781 to your computer and use it in GitHub Desktop.
Save mgreenly/1397781 to your computer and use it in GitHub Desktop.
Decorator Pattern using SimpleDelegator
require 'delegate'
class Foo
attr_accessor :fname, :lname
def initialize(fname, lname)
@fname, @lname = fname, lname
end
end
# create a foo object
foo = Foo.new('john', 'smith')
class FooDecorator < SimpleDelegator
def full_name
"#{fname} #{lname}"
end
end
# create and use a decorated foo
decorated_foo = FooDecorator.new(foo)
puts decorated_foo.full_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment