From b1999be5a7efd67e2602c37ed898aa8433661863 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Feb 2005 01:45:35 +0000 Subject: A hopefully more successful attempt at the Routing branch merge git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/inflector.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/inflector.rb') diff --git a/activesupport/lib/inflector.rb b/activesupport/lib/inflector.rb index 065fad3762..a9b2f87be4 100644 --- a/activesupport/lib/inflector.rb +++ b/activesupport/lib/inflector.rb @@ -20,11 +20,11 @@ module Inflector end def camelize(lower_case_and_underscored_word) - lower_case_and_underscored_word.to_s.gsub(/(^|_)(.)/){$2.upcase} + lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end def underscore(camel_cased_word) - camel_cased_word.to_s.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase + camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase end def humanize(lower_case_and_underscored_word) @@ -47,7 +47,13 @@ module Inflector Inflector.underscore(Inflector.demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id") end - + + def constantize(camel_cased_word) + camel_cased_word.split("::").inject(Object) do |final_type, part| + final_type = final_type.const_get(part) + end + end + private def plural_rules #:doc: [ -- cgit v1.2.3