I’m looking for a way to list all classes defined inside a module (namespace).
Here is similar question regarding the problem:
How to get all class names in a namespace in Ruby?
but see the last reply, the Module.constants is empty until the class is called/loaded. Is there any way to do this without manually referencing each class?
I’m trying to use this feature in Rails 3.2, and the only way I found was requiring each class in initializer (didn’t try it but it still requires manual typing…).
Thanks in advance for your time.
You could glob the files in a namespaced directory as such:
So in a Rails initialization file or model you could do: