mirror of https://github.com/rails/rails
Add more test case for #demodulize, Improve documentation
This commit is contained in:
parent
8c1406cf25
commit
075a1e21fa
|
@ -130,6 +130,8 @@ class String
|
|||
#
|
||||
# 'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections"
|
||||
# 'Inflections'.demodulize # => "Inflections"
|
||||
# '::Inflections'.demodulize # => "Inflections"
|
||||
# ''.demodulize # => ''
|
||||
#
|
||||
# See also +deconstantize+.
|
||||
def demodulize
|
||||
|
|
|
@ -172,6 +172,8 @@ module ActiveSupport
|
|||
#
|
||||
# 'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections"
|
||||
# 'Inflections'.demodulize # => "Inflections"
|
||||
# '::Inflections'.demodulize # => "Inflections"
|
||||
# ''.demodulize # => ''
|
||||
#
|
||||
# See also +deconstantize+.
|
||||
def demodulize(path)
|
||||
|
|
|
@ -200,6 +200,7 @@ class InflectorTest < ActiveSupport::TestCase
|
|||
def test_demodulize
|
||||
assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")
|
||||
assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")
|
||||
assert_equal "Account", ActiveSupport::Inflector.demodulize("::Account")
|
||||
assert_equal "", ActiveSupport::Inflector.demodulize("")
|
||||
end
|
||||
|
||||
|
|
|
@ -1631,6 +1631,9 @@ Given a string with a qualified constant name, `demodulize` returns the very con
|
|||
"Product".demodulize # => "Product"
|
||||
"Backoffice::UsersController".demodulize # => "UsersController"
|
||||
"Admin::Hotel::ReservationUtils".demodulize # => "ReservationUtils"
|
||||
"::Inflections".demodulize # => "Inflections"
|
||||
"".demodulize # => ""
|
||||
|
||||
```
|
||||
|
||||
Active Record for example uses this method to compute the name of a counter cache column:
|
||||
|
|
Loading…
Reference in New Issue