Created
July 30, 2010 20:29
-
-
Save altamic/501261 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Iraci < Struct.new(:name, :birth_date) | |
include Observable | |
def birth! | |
self[:birth_date] = Time.now.strftime('%d %B') | |
changed | |
notify_observers(name, birth_date) | |
end | |
end | |
class Observer | |
def initialize(observed) | |
observed.add_observer(self) | |
end | |
def update(name, birth_date) | |
puts "#{name} has been constructed on #{birth_date}" | |
end | |
end | |
unborn = Iraci.new | |
pallotron = Observer.new(unborn) | |
# Ivan, please set the name of the unborn when you | |
# and your wife will decide; once delivered, just call | |
# the birth! method on the unborn to notify the observer :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment