Skip to content

Instantly share code, notes, and snippets.

@craigw
Created December 22, 2011 12:00
Show Gist options
  • Save craigw/1510069 to your computer and use it in GitHub Desktop.
Save craigw/1510069 to your computer and use it in GitHub Desktop.
class Foo
def bar
rand(10).to_s
end
end
# My interface is the same as Foo because I just decorate that behaviour
class FooDecorator
attr_accessor :other
private :other=, :other
def initialize other
self.other = other
end
def bar
"The number is #{other.bar}"
end
end
class Foo
def bar
rand(10).to_s
end
end
class Baz
def baz
rand(100).to_s
end
end
# My interface is different to Foo or Baz, it provides convenient and consistent access to possibly several underlying objects
class FooBazPresenter
attr_accessor :foo, :baz
private :foo=, :foo, :baz=, :baz
def initialize foo, baz
self.foo = foo
self.baz = baz
end
def to_s
"Foo #{foo.bar}, Baz #{baz.bar}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment