Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread
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?


Thread View

Thread Author Date
Getting Namespace & Nesting Info InternallyDan Rathbun2009-11-24 11:25
      RE: Getting Namespace & Nesting Info InternallyDaniel Berger2010-03-17 13:37
            RE: Getting Namespace & Nesting Info InternallyDan Rathbun2010-03-26 03:44

Post a followup to this message