Skip to content
Browse files

Refactor Observer.observed_class

  • Loading branch information...
1 parent cd556c9 commit 9072a08fac61e7c692d8d70c0941839ea640a978 @oscardelben oscardelben committed Apr 17, 2012
Showing with 2 additions and 5 deletions.
  1. +2 −5 activemodel/lib/active_model/observing.rb
View
7 activemodel/lib/active_model/observing.rb
@@ -5,6 +5,7 @@
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/enumerable'
require 'active_support/deprecation'
+require 'active_support/core_ext/object/try'
require 'active_support/descendants_tracker'
module ActiveModel
@@ -212,11 +213,7 @@ def observed_classes
# The class observed by default is inferred from the observer's class name:
# assert_equal Person, PersonObserver.observed_class
def observed_class
- if observed_class_name = name[/(.*)Observer/, 1]
- observed_class_name.constantize
- else
- nil
- end
+ name[/(.*)Observer/, 1].try :constantize
end
end

0 comments on commit 9072a08

Please sign in to comment.
Something went wrong with that request. Please try again.