From aab42ccdab084dbd661d3e21d9fce15d0f3f6a06 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 23:42:12 +0100 Subject: [PATCH] AS guide: documents String#demodulize --- .../active_support_core_extensions.textile | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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: + + +"Product".demodulize # => "Product" +"Backoffice::UsersController".demodulize # => "UsersController" +"Admin::Hotel::ReservationUtils".demodulize # => "ReservationUtils" + + +Active Record for example uses this method to compute the name of a counter cache column: + + +# 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 + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- GitLab