I have several files defining nested modules, say:
File1:
module A
module B
class B1
class B1Error < Exception ; end
end
end
end
File 2:
module A
module B
class B2
class B2Error < Exception ; end
class B2_inner
end
end
end
end
I need a method to get all classes defined under a given module.
def get_all_classes_under_module_hier(hier)
???
end
get_all_classes_under_module_hier(A::B)
#=> A::B::B1, A::B::B1::B1Error, A::B::B2, A::B::B2::B2Error, A::B::B2::B2_inner.
How can I achieve the purpose?
The reason I need this is: I am trying to use log4r. I have several classes and I am creating logger with classNames on each of them. In the YAML configuration, it is required to again point out all defined logger names to configure further. I am trying to use a generic code to pull out all classes under a module hierarchy and have dynamic configuration.
Any input regarding my approach for log4r (or any simpler way) is also appreciated.
You can use either
Module::nesting
as below:or,
Module::constants