method

safe_constantize

v8.0.0 - Show latest stable - Class: String
safe_constantize()
public

safe_constantize tries to find a declared constant with the name specified in the string. It returns nil when the name is not in CamelCase or is not initialized.

'Module'.safe_constantize  # => Module
'Class'.safe_constantize   # => Class
'blargle'.safe_constantize # => nil

See ActiveSupport::Inflector.safe_constantize.

1Note

How safe is this?

amala ยท Jan 2, 2015

Could this be used against a user supplied fragment like in a url route ?