From ef79b8400f064361b2dbe1ee89f42d2adc103a3c Mon Sep 17 00:00:00 2001 From: homa Date: Tue, 28 Feb 2012 18:34:19 +0100 Subject: Inflector/constantize - inject method lets us to avoid using another variable --- activesupport/lib/active_support/inflector/methods.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index c630bd21b1..48ea5653c7 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -209,12 +209,10 @@ module ActiveSupport 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) + + names.inject(Object) do |constant, name| + constant.const_get(name, false) end - constant end # Tries to find a constant with the name specified in the argument string: -- cgit v1.2.3