From: wys@... (Clemens Wyss) Date: 2001-01-03T16:40:02+09:00 Subject: [ruby-talk:8558] Re: Observing multiple observables Kevin Smith wrote in <0G6K002IIN4WZV@mta5.snfc21.pbi.net>: <> > >The definition of add_observer would change to: > >def add_observer(object, methodSymbol = :update) > >When it comes time to actually do the update, it >calls: > >object.method(methodSymbol).call(*args) > <> ...why not go one step further (to the SmallTalk onChange:send:-update:- paradigm) and extend add_observer to: def add_observer(oberverObj, aspectOfInterest = nil, callback = :update) aspectOfInterest is the aspect of the observable object which the client (observer) is interested in (ie a Person's name or a Person's address): class Observer def add_observer(observerObj, aspect = nil, callback = :update) ... end def update(aspect = nil) ... end end class Person include Observer ... end class PersonObserver def initialize(p) p.add_observer(self, 'name', :name_of_person_changed) ... end def name_of_person_changed(object, newValue = nil) end end p = Person.new() PersonObserver.new(p) NOTE: the callback method (cuold) expect the newValue of the aspect)! Instead of adding default parameters to add_observer we could define a new method: add_observer_for(_aspect) Clemens