const = :FOO
FOO = :ok
defined? FOO => 'constant'
How to check if FOO
is defined using const
?
defined? eval( const.to_s )
does not work.
Use const_defined?
instead: http://ruby-doc.org/core/classes/Module.html#M000487
Object.const_defined?(const.to_s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With