Skip to content

Instantly share code, notes, and snippets.

@altamic
Created July 30, 2010 20:29
Show Gist options
  • Save altamic/501261 to your computer and use it in GitHub Desktop.
Save altamic/501261 to your computer and use it in GitHub Desktop.
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