Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.