diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 8 |
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) |