Ask a Question related to Ruby, Design and Development.

  1. #1

    Default const_missing

    I just tried to use const_missing (which I think is a
    neat idea).

    Shouldn't it work at the top level? Am I doing something
    wrong?

    def const_missing
    "not found"
    end

    p FOO

    The above gives an error.

    Hal

    --
    Hal Fulton
    [email]hal9000@hypermetrics.com[/email]


    Hal E. Fulton Guest

  2. Similar Questions and Discussions

    1. Using Module#const_missing for resolving "external" classes
      Would it be possible to use const_missing to resolve external classes? Ie, I imagine doing something like this class Module def...
  3. #2

    Default Re: const_missing

    Hal E. Fulton wrote:
    > I just tried to use const_missing (which I think is a
    > neat idea).
    >
    > Shouldn't it work at the top level? Am I doing something
    > wrong?
    >
    > def const_missing
    > "not found"
    > end
    This should be

    ---
    def Object.const_missing(sym)
    p sym
    end

    Foo
    ---

    /Christoph

    Christoph R. Guest

  4. #3

    Default Re: const_missing

    Hal E. Fulton wrote:

    ....
    > The above gives an error.

    On second thought your implementation could
    have worked - the following may sheet more light
    (confusion in my case;-) on it ...

    --
    def const_missing(sym)
    p sym
    end

    def const_missingx(sym)
    p sym
    end

    public :const_missing,:const_missingx
    Object.const_missingx(:K) # :K
    Object.const_missing(:K) # throws a NameError ???
    ---

    /Christoph

    Christoph R. Guest

  5. #4

    Default Re: const_missing

    here's an example, for followers, since google brought me quickly here:



    class Object
    def self.const_missing c
    p 'const is', c
    end
    end
    Roger Deloy Pack is offline Junior Member
    Join Date
    Sep 2010
    Posts
    1

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139