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
|
@ -210,11 +210,9 @@ module ActiveSupport
|
||||||
names = camel_cased_word.split('::')
|
names = camel_cased_word.split('::')
|
||||||
names.shift if names.empty? || names.first.empty?
|
names.shift if names.empty? || names.first.empty?
|
||||||
|
|
||||||
constant = Object
|
names.inject(Object) do |constant, name|
|
||||||
names.each do |name|
|
constant.const_get(name, false)
|
||||||
constant = constant.const_get(name, false)
|
|
||||||
end
|
end
|
||||||
constant
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tries to find a constant with the name specified in the argument string:
|
# Tries to find a constant with the name specified in the argument string:
|
||||||
|
|
Loading…
Reference in a new issue