Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…variable
  • Loading branch information...
commit ef79b8400f064361b2dbe1ee89f42d2adc103a3c 1 parent 699ba8a
@homakov homakov authored
Showing with 3 additions and 5 deletions.
  1. +3 −5 activesupport/lib/active_support/inflector/methods.rb
View
8 activesupport/lib/active_support/inflector/methods.rb
@@ -209,12 +209,10 @@ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
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:
Please sign in to comment.
Something went wrong with that request. Please try again.