aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector/methods.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-10-29 01:07:54 -0700
committerXavier Noria <fxn@hashref.com>2011-10-29 01:07:54 -0700
commit0fc531392d1f606054a6d6e394304c72a846d4c8 (patch)
treea272ee64d7012b0f182ac8e3b93e1cfb6a866973 /activesupport/lib/active_support/inflector/methods.rb
parent2e74334abdf7df2b663cd96711693d710cffdccc (diff)
downloadrails-0fc531392d1f606054a6d6e394304c72a846d4c8.tar.gz
rails-0fc531392d1f606054a6d6e394304c72a846d4c8.tar.bz2
rails-0fc531392d1f606054a6d6e394304c72a846d4c8.zip
let demodulize do less work, and add tests
This is also faster on 1.9.
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 934529d496..454637191e 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -166,7 +166,9 @@ module ActiveSupport
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
# "Inflections".demodulize # => "Inflections"
def demodulize(class_name_in_module)
- class_name_in_module.to_s.gsub(/^.*::/, '')
+ # If you remove the module part of an empty string, you get an empty string.
+ # That's why the regexp uses the * quantifier.
+ class_name_in_module.to_s[/[^:]*\z/]
end
# Creates a foreign key name from a class name.