diff options
author | Joe Van Dyk <joe@fixieconsulting.com> | 2010-04-12 11:09:49 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-04-12 11:09:49 +0200 |
commit | ccf33660a1548dadd123a92df6de2de946d208c4 (patch) | |
tree | d7340112a52a88d8123e5289c483f1b4931a6260 /activesupport/lib/active_support/inflector/methods.rb | |
parent | bab1f910c7399fcfe9f031a1ce3a1f36bf5fd277 (diff) | |
download | rails-ccf33660a1548dadd123a92df6de2de946d208c4.tar.gz rails-ccf33660a1548dadd123a92df6de2de946d208c4.tar.bz2 rails-ccf33660a1548dadd123a92df6de2de946d208c4.zip |
Avoid unnecessary allocations in Inflector.underscore [#3626 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index c7df62e915..b3dc5b2f3a 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -36,11 +36,13 @@ module ActiveSupport # "ActiveRecord".underscore # => "active_record" # "ActiveRecord::Errors".underscore # => active_record/errors def underscore(camel_cased_word) - camel_cased_word.to_s.gsub(/::/, '/'). - gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). - gsub(/([a-z\d])([A-Z])/,'\1_\2'). - tr("-", "_"). - downcase + word = camel_cased_word.to_s.dup + word.gsub!(/::/, '/') + word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') + word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') + word.tr!("-", "_") + word.downcase! + word end # Replaces underscores with dashes in the string. |