Skip to content

Instantly share code, notes, and snippets.

@jordelver
Created August 1, 2012 20:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jordelver/3230399 to your computer and use it in GitHub Desktop.
Save jordelver/3230399 to your computer and use it in GitHub Desktop.
Ruby simple delegator
# Example from http://mikepackdev.com/blog_posts/31-exhibit-vs-presenter
class Decorator < SimpleDelegator
end
class Car
def price
1_000_000
end
end
car = Car.new
car.price
=> 1000000
decorated_car = Decorator.new(car)
decorated_car.price
=> 1000000
class CarWithHeatedSeats < Decorator
def price
super + 5_000
end
end
car = CarWithHeatedSeats.new(car)
car.price
=> 1005000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment