| Message: 91724 |
 |
BY: Dan Rathbun (danzoid61) DATE: 2009-11-24 11:25 SUBJECT: Getting Namespace & Nesting Info Internally in Windows/api.rb, line 166, Dan et al, poses the question, viz:
"# TODO: If there's a way to automatically grab the namespace internally, nesting and all, I'd love to know the solution."
ANS: class Module, has class method: "nesting"
(from the book):
Module.nesting -> anArray
Returns the list of Modules nested at the point of call.
code example:
module M1
module M2
$a = Module.nesting
end
end
$a » [M1::M2, M1]
$a[0].name » "M1::M2"
Also note the Module class instance method:
self.included_modules -> Array
which is sort of the opposite, it looks down instead of up; and makes an array of included modules.
An there's also:
self.ancestors -> Array
Makes an array of module "self's" superclasses.
Is that the answer ya' was looking for? | |