# Observer pattern

**URL:** <https://www.ruby-forum.com/t/observer-pattern/61806>\
**Category:** Ruby\
**Created:** [May 27, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/observer-pattern/61806 "2006-05-27T19:49:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![madan\_m](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/cab0a1/32.png) [@madan\_m](https://www.ruby-forum.com/u/madan_m)\
**Post date:** [May 27, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/observer-pattern/61806/1 "2006-05-27T19:49:41Z")

</div>

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.
