Inflector/constantize - inject method lets us to avoid using another variable

This commit is contained in:
homa 2012-02-28 18:34:19 +01:00
parent 699ba8ab52
commit ef79b8400f
1 changed files with 3 additions and 5 deletions

View File

@ -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: