Skip to content

Instantly share code, notes, and snippets.

@tjackiw
Created December 19, 2012 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjackiw/4335648 to your computer and use it in GitHub Desktop.
Save tjackiw/4335648 to your computer and use it in GitHub Desktop.
Design Patterns: Observer Pattern in Ruby
car = Car.new(2300)
car.log(100)
=> "The car has logged 100 miles, totaling 2400 miles traveled."
car.log(354)
=> "The car has logged 354 miles, totaling 2754 miles traveled."
car.log(300)
=> "The car has logged 300 miles, totaling 3054 miles traveled."
=> "The car needs to be taken in for service!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment