From: John Small Date: 2001-01-04T01:56:48+09:00 Subject: [ruby-talk:8571] If Observable#notify_observers returned true/false then false could imply veto of change Hi, If Observable#notify_observers were changed from def notify_observers(*arg) if defined? @observer_state and @observer_state if defined? @observer_peers for i in @observer_peers.dup i.update(*arg) end end @observer_state = false end end to def notify_observers(*arg) veto = false if defined? @observer_state and @observer_state if defined? @observer_peers for i in @observer_peers.dup veto ||= !i.update(*arg) end end @observer_state = false end !veto end then an updated observer could have the option of vetoing the proposed change: require 'observer' class Foo include Observable def constrainedProperty @constrainedProperty end def constrainedProperty=(newValue) changed if notify_observers(self, :constrainedProperty,@constrainedProperty,newValue) @constrainedProperty = newValue true else false end end def boundProperty @boundProperty end def boundProperty=(newValue) oldValue = @boundProperty @boundProperty = newValue changed notify_observers(self,:boundProperty,oldValue,newValue) end def initialize @constrainedProperty = @boundProperty = 1 end end class FooObserver def update(object,property,oldValue,newValue) if object.kind_of?(Foo) case property when :constrainedProperty return false if oldValue == newValue return true end end end end f = Foo.new fo = FooObserver.new f.add_observer(fo) f.constrainedProperty = 1 # => false: useless change f.constrainedProperty = 2 # => true: I approve f.boundProperty = 3 # => thanks for letting me know! John