mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Inflector/constantize - inject method lets us to avoid using another variable
This commit is contained in:
parent
699ba8ab52
commit
ef79b8400f
1 changed files with 3 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue