Permalink
Browse files

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

…variable
  • Loading branch information...
1 parent 699ba8a commit ef79b8400f064361b2dbe1ee89f42d2adc103a3c @homakov homakov committed Feb 28, 2012
Showing with 3 additions and 5 deletions.
  1. +3 −5 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:

0 comments on commit ef79b84

Please sign in to comment.