Method: Inflections.safe_constantize

Defined in:
lib/build/ExtendedString.rb

.safe_constantize(camel_cased_word) ⇒ Object

Tries to find a constant with the name specified in the argument string.



384
385
386
387
388
389
390
391
# File 'lib/build/ExtendedString.rb', line 384

def safe_constantize(camel_cased_word)
  constantize(camel_cased_word)
rescue NameError => e
  raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
    e.name.to_s == camel_cased_word.to_s
rescue ArgumentError => e
  raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
end