aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2005-11-16 00:56:16 +0000
committerNicholas Seckar <nseckar@gmail.com>2005-11-16 00:56:16 +0000
commit1cc8ab865fb0b36df1d202ea4d08952d2881d347 (patch)
tree2773c3f929b03094a9d08b3a07d676e60e21b0e4 /activesupport/lib
parentc98011bc32ac892f38bbda15b485c87a35795bba (diff)
downloadrails-1cc8ab865fb0b36df1d202ea4d08952d2881d347.tar.gz
rails-1cc8ab865fb0b36df1d202ea4d08952d2881d347.tar.bz2
rails-1cc8ab865fb0b36df1d202ea4d08952d2881d347.zip
Change Inflector#constantize to use eval instead of const_get
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3049 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/inflector.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 7009628cb3..2e69b74c54 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -142,9 +142,11 @@ module Inflector
end
def constantize(camel_cased_word)
- camel_cased_word.split("::").inject(Object) do |final_type, part|
- final_type = final_type.const_get(part)
- end
+ raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" unless
+ camel_cased_word.split("::").all? { |part| /^[A-Z]\w*$/ =~ part }
+
+ camel_cased_word = "::#{camel_cased_word}" unless camel_cased_word[0, 2] == '::'
+ Object.module_eval(camel_cased_word, __FILE__, __LINE__)
end
def ordinalize(number)