From 199ccb494fd867b82b6af4f9e70a7d704f082be0 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Sun, 24 Aug 2008 15:41:08 +0200 Subject: [PATCH] Simplified the #constantize method, making it use #inject instead of #each. --- activesupport/lib/active_support/inflector.rb | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-) diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 7ae9e0c..26fd95d 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -303,22 +303,18 @@ module ActiveSupport names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? - constant = Object - names.each do |name| - constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) + names.inject(Object) do |constant, name| + constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end - constant end else def constantize(camel_cased_word) #:nodoc: names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? - constant = Object - names.each do |name| - constant = constant.const_get(name, false) || constant.const_missing(name) + names.inject(Object) do |constant, name| + constant.const_get(name, false) || constant.const_missing(name) end - constant end end -- 1.5.4.3