From 1cc8ab865fb0b36df1d202ea4d08952d2881d347 Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Wed, 16 Nov 2005 00:56:16 +0000 Subject: 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 --- activesupport/lib/active_support/inflector.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') 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) -- cgit v1.2.3