Skip to content

Instantly share code, notes, and snippets.

@stengland
Forked from jordelver/gist:3230399
Created August 14, 2012 09:07
Show Gist options
  • Save stengland/3347696 to your computer and use it in GitHub Desktop.
Save stengland/3347696 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