diff options
| author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-11 09:46:22 -0300 | 
|---|---|---|
| committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-11 09:46:22 -0300 | 
| commit | d0b5484b5d039a1d08f79652011d40c7a829d6ef (patch) | |
| tree | 84d9c0224d0e8e2fbcf87e34dc7097679c32a196 | |
| parent | 142448259d7f450df49fdac06bf912edfecaa633 (diff) | |
| parent | 075a1e21fa59433976dd6860b775a280db10f606 (diff) | |
| download | rails-d0b5484b5d039a1d08f79652011d40c7a829d6ef.tar.gz rails-d0b5484b5d039a1d08f79652011d40c7a829d6ef.tar.bz2 rails-d0b5484b5d039a1d08f79652011d40c7a829d6ef.zip | |
Merge pull request #14705 from akshay-vishnoi/doc_changes
Add more test case for #demodulize, Improve documentation
4 files changed, 8 insertions, 0 deletions
| diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index cf9b1a4ec0..18273573e0 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -130,6 +130,8 @@ class String    #    #   'ActiveRecord::CoreExtensions::String::Inflections'.demodulize # => "Inflections"    #   'Inflections'.demodulize                                       # => "Inflections" +  #   '::Inflections'.demodulize                                     # => "Inflections" +  #   ''.demodulize                                                  # => ''    #    # See also +deconstantize+.    def demodulize diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index a270c4452f..6229d15619 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -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) diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 35967ba656..b0b4738eb3 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -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 diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index f08a85770f..834c94e2ec 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -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: | 
