summaryrefslogtreecommitdiff
path: root/lib/observer.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-04-10 05:48:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-04-10 05:48:43 +0000
commit7194267b3bdf68ad75bd6bee8e7c6377f7b0ea2f (patch)
tree6dcd08ef584fc777cf34517136d5ce3948840e45 /lib/observer.rb
parentbe72d9a5da9be284d2bdb8047e50f14e014b7835 (diff)
2000-04-10
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/observer.rb')
-rw-r--r--lib/observer.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/observer.rb b/lib/observer.rb
index a91c1e38c31..08e75f51255 100644
--- a/lib/observer.rb
+++ b/lib/observer.rb
@@ -4,20 +4,20 @@
module Observable
def add_observer(observer)
- @observer_peers = [] unless @observer_peers
+ @observer_peers = [] unless defined? @observer_peers
unless defined? observer.update
raise NameError, "observer needs to respond to `update'"
end
@observer_peers.push observer
end
def delete_observer(observer)
- @observer_peers.delete observer if @observer_peers
+ @observer_peers.delete observer if defined? @observer_peers
end
def delete_observers
- @observer_peers.clear if @observer_peers
+ @observer_peers.clear if defined? @observer_peers
end
def count_observers
- if @observer_peers
+ if defined? @observer_peers
@observer_peers.size
else
0
@@ -27,11 +27,15 @@ module Observable
@observer_state = state
end
def changed?
- @observer_state
+ if defined? @observer_state and @observer_state
+ true
+ else
+ false
+ end
end
def notify_observers(*arg)
- if @observer_state
- if @observer_peers
+ if defined? @observer_state and @observer_state
+ if defined? @observer_peers
for i in @observer_peers.dup
i.update(*arg)
end