aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/inflections.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-10-29 18:03:35 -0700
committerXavier Noria <fxn@hashref.com>2011-10-29 18:10:45 -0700
commit11f6795b238172c4a13176062bd38b83285799b7 (patch)
treea70a883974bf91bbecb4ca11d26409243eaf9a30 /activesupport/lib/active_support/core_ext/string/inflections.rb
parent8ef1bd9b293678b3d9c07a3f63384781df78b6ad (diff)
downloadrails-11f6795b238172c4a13176062bd38b83285799b7.tar.gz
rails-11f6795b238172c4a13176062bd38b83285799b7.tar.bz2
rails-11f6795b238172c4a13176062bd38b83285799b7.zip
defines Module#qualified_const_(defined?|get|set) and String#deconstantize
This commit also implements a faster version of #demodulize I was unable to isolate with git add --patch. Not a big fan of the name #deconstantize. It complements #demodulize getting rid of the rightmost constant, hence the name, but it is unrelated to the well-known #constantize. So unsure. Could not come with anything better, please feel free to rename.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/inflections.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb15
1 files changed, 15 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 fd91b3cacb..9356940650 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -117,10 +117,25 @@ class String
#
# "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
# "Inflections".demodulize # => "Inflections"
+ #
+ # See also +deconstatize+.
def demodulize
ActiveSupport::Inflector.demodulize(self)
end
+ # Removes the rightmost segment from the constant expression in the string.
+ #
+ # "Net::HTTP".deconstantize # => "Net"
+ # "::Net::HTTP".deconstantize # => "::Net"
+ # "String".deconstantize # => ""
+ # "::String".deconstantize # => ""
+ # "".deconstantize # => ""
+ #
+ # See also +demodulize+.
+ def deconstantize
+ ActiveSupport::Inflector.deconstantize(self)
+ end
+
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
#
# ==== Examples