aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/observer.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-10 19:39:09 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-10 19:39:09 +0200
commitb67ec8ba20099c8b39bf344f385bbbd2b9c8f47d (patch)
tree008a576bb72baffd49b2483b3b08e181933e29c1 /activerecord/lib/active_record/observer.rb
parentc4d6245e875bbb276c122a5a401422d341dac4df (diff)
downloadrails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.tar.gz
rails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.tar.bz2
rails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.zip
class_attribute is not a direct replacement of class_inheritable_*.
If you are setting a hash or an array in class_attribute or you need to freeze it, to ensure people won't modify it in place or you need to dup it on inheritance.
Diffstat (limited to 'activerecord/lib/active_record/observer.rb')
-rw-r--r--activerecord/lib/active_record/observer.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/observer.rb b/activerecord/lib/active_record/observer.rb
index ed0f039597..0ea7fe7365 100644
--- a/activerecord/lib/active_record/observer.rb
+++ b/activerecord/lib/active_record/observer.rb
@@ -88,7 +88,7 @@ module ActiveRecord
#
class Observer < ActiveModel::Observer
class_attribute :observed_methods
- self.observed_methods = []
+ self.observed_methods = [].freeze
def initialize
super
@@ -97,7 +97,11 @@ module ActiveRecord
def self.method_added(method)
method = method.to_sym
- observed_methods << method if ActiveRecord::Callbacks::CALLBACKS.include?(method)
+
+ if ActiveRecord::Callbacks::CALLBACKS.include?(method)
+ self.observed_methods += [method]
+ self.observed_methods.freeze
+ end
end
protected