rails/rails — pull request #6068 by frodsan (2012-04-29 23:58:32+00:00)
Title: observed_classes get redefined properly - fixes #3505

I'm trying to fix #3505 issue:

I need help with this:

rails/activemodel/lib/active_model/observing.rb:199: warning: previous definition of observed_classes was here
rails/activemodel/lib/active_model/observing.rb:199: warning: method redefined; discarding old observed_classes

I'm getting those warnings in this test:

test "passes observers to subclasses" do
FooObserver.instance
bar = Class.new(Foo)
assert_equal Foo.observers_count, bar.observers_count
end

I don't know how to check if the method is already defined in the subclass?

def observe(*models)
models.flatten!
models.collect! { |model| model.respond_to?(:to_sym) ? model.to_s.camelize.constantize : model }

unless self.singleton_class.respond_to?(:observed_classes)
define_singleton_method(:observed_classes) { models }
end
end