lib/active_support/inflector.rb in activesupport-1.4.0 vs lib/active_support/inflector.rb in activesupport-1.4.1
- old
+ new
@@ -241,15 +241,14 @@
#
# Examples
# "Module".constantize #=> Module
# "Class".constantize #=> Class
def constantize(camel_cased_word)
- unless /^(::)?([A-Z]\w*)(::[A-Z]\w*)*$/ =~ camel_cased_word
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
- camel_cased_word = "::#{camel_cased_word}" unless $1
- Object.module_eval(camel_cased_word, __FILE__, __LINE__)
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
end
# Ordinalize turns a number into an ordinal string used to denote the
# position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
#