aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/inflector.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 01:45:35 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 01:45:35 +0000
commitb1999be5a7efd67e2602c37ed898aa8433661863 (patch)
tree03bc833276075d802d0ce0ad261baed3d7232533 /activesupport/lib/inflector.rb
parent88a3343ed57c01ca358da8473d15fc4d2b4a5bff (diff)
downloadrails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.gz
rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.bz2
rails-b1999be5a7efd67e2602c37ed898aa8433661863.zip
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
Diffstat (limited to 'activesupport/lib/inflector.rb')
-rw-r--r--activesupport/lib/inflector.rb12
1 files changed, 9 insertions, 3 deletions
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:
[