diff options
author | Subba Rao Pasupuleti <subbarao.pasupuleti@gmail.com> | 2010-08-31 17:46:34 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-01 13:59:53 +0200 |
commit | 2d74ed49f4513572b102ce82696a6f62335a1841 (patch) | |
tree | a301bb1cda90311bae0b1f6d7c04309ae5100311 | |
parent | 02480a897be25c24f59180513d37649a31ad3835 (diff) | |
download | rails-2d74ed49f4513572b102ce82696a6f62335a1841.tar.gz rails-2d74ed49f4513572b102ce82696a6f62335a1841.tar.bz2 rails-2d74ed49f4513572b102ce82696a6f62335a1841.zip |
reader method eliminates defined? checks
Signed-off-by: José Valim <jose.valim@gmail.com>
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index 2c2ff8f5d5..0d2dd36e59 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -34,6 +34,11 @@ module ActiveModel @observers ||= [] end + # Gets the current observer instances. + def observer_instances + @observer_instances ||= [] + end + # Instantiate the global Active Record observers. def instantiate_observers observers.each { |o| instantiate_observer(o) } @@ -43,20 +48,17 @@ module ActiveModel unless observer.respond_to? :update raise ArgumentError, "observer needs to respond to `update'" end - @observer_instances ||= [] - @observer_instances << observer + observer_instances << observer end def notify_observers(*arg) - if defined? @observer_instances - for observer in @observer_instances - observer.update(*arg) - end + for observer in observer_instances + observer.update(*arg) end end def count_observers - @observer_instances.size + observer_instances.size end protected |