lib/active_support/inflector.rb in activesupport-1.2.3 vs lib/active_support/inflector.rb in activesupport-1.2.4

- old
+ new

@@ -140,12 +140,14 @@ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true) underscore(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 + 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) if (11..13).include?(number.to_i % 100) "#{number}th"