diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 4 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 2 |
2 files changed, 5 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. diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 5c956e0075..7d15b3c7e5 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -194,6 +194,8 @@ class InflectorTest < Test::Unit::TestCase def test_demodulize assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account") + assert_equal "Account", ActiveSupport::Inflector.demodulize("Account") + assert_equal "", ActiveSupport::Inflector.demodulize("") end def test_foreign_key |