aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-03-01 23:42:12 +0100
committerXavier Noria <fxn@hashref.com>2010-03-01 23:42:12 +0100
commitaab42ccdab084dbd661d3e21d9fce15d0f3f6a06 (patch)
tree6ca13e23ac12adbe288f6c31f2c2d9bb46c4876c /railties/guides/source/active_support_core_extensions.textile
parent44bd3bd4ff2705b798313fbbb60cb7064b328f9b (diff)
downloadrails-aab42ccdab084dbd661d3e21d9fce15d0f3f6a06.tar.gz
rails-aab42ccdab084dbd661d3e21d9fce15d0f3f6a06.tar.bz2
rails-aab42ccdab084dbd661d3e21d9fce15d0f3f6a06.zip
AS guide: documents String#demodulize
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile25
1 files changed, 25 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index e56dde2977..307f7eddb3 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1412,6 +1412,31 @@ end
NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+h5. +demodulize+
+
+Given a string with a qualified constant reference expression, +demodulize+ returns the very constant name, that is, the rightmost part of it:
+
+<ruby>
+"Product".demodulize # => "Product"
+"Backoffice::UsersController".demodulize # => "UsersController"
+"Admin::Hotel::ReservationUtils".demodulize # => "ReservationUtils"
+</ruby>
+
+Active Record for example uses this method to compute the name of a counter cache column:
+
+<ruby>
+# active_record/reflection.rb
+def counter_cache_column
+ if options[:counter_cache] == true
+ "#{active_record.name.demodulize.underscore.pluralize}_count"
+ elsif options[:counter_cache]
+ options[:counter_cache]
+ end
+end
+</ruby>
+
+NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+
h3. Extensions to +Numeric+
h4. Bytes