Method: Observable#add_observer
- Defined in:
- lib/fable/observer.rb
#add_observer(observer, func = :update) ⇒ Object
Add observer as an observer on this object. So that it will receive notifications.
observer-
the object that will be notified of changes.
func-
Symbol naming the method that will be called when this Observable has changes.
This method must return true for
observer.respond_to?and will receive*argwhen #notify_observers is called, where*argis the value passed to #notify_observers by this Observable
129 130 131 132 133 134 135 |
# File 'lib/fable/observer.rb', line 129 def add_observer(observer, func=:update) @observer_peers = {} unless defined? @observer_peers unless observer.respond_to? func raise NoMethodError, "observer does not respond to `#{func}'" end @observer_peers[observer] = func end |