I'm dynamically defining a module name from an argument passed on the cli, for example Required::Module::#{ARGV.first}
Is there any way to check if that module exists? Also, how would I run methods on it not knowing it's exact name?
Use const_defined?
for this.
Required::Module.const_defined?(:ModuleName)
returns true or false.
defined?(Required::Module)
gives "constant"
if it exists, and nil
if it doesn't.
Update: Sorry, didn't read your question properly.
defined?(eval("Required::Module::"+string))
should give you what you're after.
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