Skip to content

Commit ef79b84

Browse files
committed
Inflector/constantize - inject method lets us to avoid using another variable
1 parent 699ba8a commit ef79b84

File tree

1 file changed

+3
-5
lines changed
  • activesupport/lib/active_support/inflector

1 file changed

+3
-5
lines changed

activesupport/lib/active_support/inflector/methods.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,10 @@ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
209209
def constantize(camel_cased_word) #:nodoc:
210210
names = camel_cased_word.split('::')
211211
names.shift if names.empty? || names.first.empty?
212-
213-
constant = Object
214-
names.each do |name|
215-
constant = constant.const_get(name, false)
212+
213+
names.inject(Object) do |constant, name|
214+
constant.const_get(name, false)
216215
end
217-
constant
218216
end
219217

220218
# Tries to find a constant with the name specified in the argument string:

0 commit comments

Comments
 (0)