Using Module#const_missing for resolving "external" classes

Discussion in 'Ruby' started by Thomas, Sep 1, 2003.

  1. Thomas

    Thomas Guest

    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
    Thomas, Sep 1, 2003
    #1
    1. Advertising

  2. Thomas

    Thomas Guest

    > How would I go about doing this?

    Never mind, I think I got it figured out.

    Cheers,

    Thomas
    Thomas, Sep 1, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Uche Ogbuji
    Replies:
    0
    Views:
    413
    Uche Ogbuji
    Aug 22, 2003
  2. Michael Schuerig

    Rake & gems: Resolving external symlinks?

    Michael Schuerig, Jul 10, 2005, in forum: Ruby
    Replies:
    0
    Views:
    102
    Michael Schuerig
    Jul 10, 2005
  3. El Barto
    Replies:
    2
    Views:
    102
    Simon Kröger
    Oct 5, 2005
  4. Replies:
    3
    Views:
    73
  5. Clifford Heath
    Replies:
    3
    Views:
    95
    Clifford Heath
    Mar 20, 2007
Loading...

Share This Page