lib/patience/core_ext/string.rb
# Constantize tries to find a declared constant with the name specified
# in the string. It raises a NameError when the name is not in CamelCase
# or is not initialized.
# Example:
#   "Module".constantize #=> Module
#   "Class".constantize  #=> Class
#   "yadda".constantize  #=> NameError: yadda is not a valid constant name!
#
Constantize tries to find a declared constant with the name specified
in the string. It raises a NameError when the name is not in CamelCase
or is not initialized.
Constantize tries to find a declared constant with the name specified in the string . It raises a NameError when the name is not in CamelCase or is not initialized .
def constantize
      unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
        raise NameError, "#{self.inspect} is not a valid constant name!"
      end
      Object.module_eval("::#{$1}", __FILE__, __LINE__)
    end
def constantize unless / \A (?:::)?([A-Z] \w *(?:::[A-Z] \w *)*) \z / =~ self raise NameError , "#{self.inspect} is not a valid constant name!" end Object . module_eval ( "::#{$1}" , __FILE__ , __LINE__ ) end
Constantize tries to find a declared constant with the name specified
in the string.
Constantize tries to find a declared constant with the name specified in the string .