Method: Extlib::Inflection.constantize
- Defined in:
- lib/aqua/support/string_extensions.rb
.constantize(camel_cased_word) ⇒ Object
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.
92 93 94 95 96 97 98 |
# File 'lib/aqua/support/string_extensions.rb', line 92 def constantize(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 Object.module_eval("::#{$1}", __FILE__, __LINE__) end |