Using Module#const_missing for resolving "external" classes

T

Thomas

Would it be possible to use const_missing to resolve external classes?
Ie, I imagine doing something like this

class Module
def const_missing(aSymbol)
# Look for aSymbol.to_s among the externally defined classes
# If it is there return a ruby object that wraps it
end
end

The problem is, how would you implement it, so it searches in the
right namespaces? Ruby searches through from the inner most scope an
outwards when it looks for a constant, and if it doesn't find it ends
up calling const_missing on the module where the constant is
referenced. Is there a way figure out exactly what scopes have been
searched for the constant and in what order?

If I could somehow get a complete ordered list of Modules and Classes
that are searched including those that have been (transitively)
included, that would make my day.

How would I go about doing this?

Cheers,

Thomas
 
T

Thomas

How would I go about doing this?

Never mind, I think I got it figured out.

Cheers,

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top