What is undefined?

Discussion in 'Ruby' started by Seebs, Aug 14, 2011.

  1. Seebs

    Seebs Guest

    Poking around, I ran into an interesting thing; nil.object_id == 0x4, but
    there's another magical object_id, 0x6, which shows up in the Ruby source
    as "Qundef".

    .... But what does it *do*? How have I managed to use Ruby for a few things
    here and there and never once encounter this value? It it used purely
    internally, and never exposed to Ruby code, or what?

    (And if you could tell me where I should have gone to look this up, that'd
    be cool too; I tried a couple of times to find stuff but eventually gave
    up on finding anything other than code snippets and patches which were
    focused on explaining some other aspect of the interpreter code.)

    Seebs, Aug 14, 2011
    1. Advertisements

  2. You'll find this in error.c:

    if (x == Qundef) {
    rb_bug("undef leaked to the Ruby space");

    http://www.google.com/codesearch#kO...kage:ruby lang:^c$ file:error.c&type=cs&l=284
    Try this:

    http://www.google.com/codesearch#search/&q=Qundef package:ruby lang:^c$&type=cs

    Or search through sources with something like

    $ find . -type f -name '*.c' -print0 \
    | xargs -r0 fgrep -n Qundef

    Kind regards

    Robert Klemme, Aug 15, 2011
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.