Forum: Ruby Observer pattern ...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
508bca331a21d64d298561f1079b4113?d=identicon&s=25 Madan Manoharan (Guest)
on 2006-05-27 19:49
(Received via mailing list)
Hello:

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'"
    end
    @observer_peers.push observer
  end

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
@observer_peers.include?(observer)


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

Thanks,
Madan.
This topic is locked and can not be replied to.