Created
August 29, 2010 13:00
-
-
Save erubboli/556264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "observer" | |
class Currency | |
include Observable | |
def initialize(symbol,rate) | |
@rate = rate | |
@symbol = symbol | |
end | |
def rate=(new_rate) | |
changed if new_rate != @rate | |
@rate = new_rate | |
notify_observers(@symbol,@rate) | |
end | |
end | |
class Graph | |
def initialize(currencies) | |
currencies.each do |currency| | |
currency.add_observer(self) | |
end | |
end | |
def update(symbol, rate) | |
puts "new rate for #{symbol} : #{rate}" | |
#.. update the graph | |
end | |
end | |
eur = Currency.new('EUR',1.2768) | |
usd = Currency.new('USD',1) | |
graph = Graph.new [eur,usd] | |
eur.rate = 1.2767 #=> new rate for EUR : 1.2767 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment