Skip to content

Commit

Permalink
Refactor Observer.observed_class
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardelben committed Apr 25, 2012
1 parent cd556c9 commit 9072a08
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions activemodel/lib/active_model/observing.rb
Expand Up @@ -5,6 +5,7 @@
require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/enumerable' require 'active_support/core_ext/enumerable'
require 'active_support/deprecation' require 'active_support/deprecation'
require 'active_support/core_ext/object/try'
require 'active_support/descendants_tracker' require 'active_support/descendants_tracker'


module ActiveModel module ActiveModel
Expand Down Expand Up @@ -212,11 +213,7 @@ def observed_classes
# The class observed by default is inferred from the observer's class name: # The class observed by default is inferred from the observer's class name:
# assert_equal Person, PersonObserver.observed_class # assert_equal Person, PersonObserver.observed_class
def observed_class def observed_class
if observed_class_name = name[/(.*)Observer/, 1] name[/(.*)Observer/, 1].try :constantize
observed_class_name.constantize
else
nil
end
end end
end end


Expand Down

0 comments on commit 9072a08

Please sign in to comment.