From 9072a08fac61e7c692d8d70c0941839ea640a978 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Tue, 17 Apr 2012 15:12:55 +0200 Subject: [PATCH] Refactor Observer.observed_class --- activemodel/lib/active_model/observing.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index a6b6dfafe7..35b1a1f0c7 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -5,6 +5,7 @@ require 'active_support/core_ext/module/remove_method' 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 @@ module ActiveModel # 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