Forum: Ruby Observer pattern ...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Madan M. (Guest)
on 2006-05-27 21:49
(Received via mailing list)

I am using the observer pattern that comes with the standard Ruby
distribution and found that the publisher allows the same observer
to be 'added' more than once.

code from observer.rb

  def add_observer(observer)
    @observer_peers = [] unless defined? @observer_peers
    unless observer.respond_to? :update
      raise NoMethodError, "observer needs to respond to `update'"
    @observer_peers.push observer

I was wondering if it would make sense to change the last but one
line in method 'add_observer' to

@observer_peers.push observer      if not

In other words, am I missing an obvious reason for a publisher to
allow an observer to register more than once?

This topic is locked and can not be replied to.