mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
let demodulize do less work, and add tests
This is also faster on 1.9.
This commit is contained in:
parent
2e74334abd
commit
0fc531392d
2 changed files with 5 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue