diff options
author | homa <homakov@gmail.com> | 2012-02-28 18:34:19 +0100 |
---|---|---|
committer | homa <homakov@gmail.com> | 2012-02-28 18:34:19 +0100 |
commit | ef79b8400f064361b2dbe1ee89f42d2adc103a3c (patch) | |
tree | 635ad0f4ec31f1d51f061878c8cc2c078b581353 | |
parent | 699ba8ab52973bf0499643235f162734fb644ab7 (diff) | |
download | rails-ef79b8400f064361b2dbe1ee89f42d2adc103a3c.tar.gz rails-ef79b8400f064361b2dbe1ee89f42d2adc103a3c.tar.bz2 rails-ef79b8400f064361b2dbe1ee89f42d2adc103a3c.zip |
Inflector/constantize - inject method lets us to avoid using another variable
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index c630bd21b1..48ea5653c7 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -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: |