ri strangeness

Discussion in 'Ruby' started by martinus, Feb 16, 2005.

  1. martinus

    martinus Guest

    Hi! I am currently writing a simple FXRuby GUI for RI (soon to be
    available on rubyforge, if it gets approoved :). I have noticed some
    strange behaviours, which can be easily reproduced like this:

    type 'ri !': information for NameError::message::! shows up.

    type 'ri message::!' Bad argument: message::!

    How does one define a method called just '!' ?
    And how can it be 'message ' and not Message'?
    strange, strange...

    martinus
     
    martinus, Feb 16, 2005
    #1
    1. Advertising

  2. martinus wrote:

    > Hi! I am currently writing a simple FXRuby GUI for RI (soon to be
    > available on rubyforge, if it gets approoved :). I have noticed some
    > strange behaviours, which can be easily reproduced like this:
    >
    > type 'ri !': information for NameError::message::! shows up.
    >
    > type 'ri message::!' Bad argument: message::!
    >
    > How does one define a method called just '!' ?


    Class.new { define_method:)"!") { ... } }

    > And how can it be 'message ' and not Message'?
    > strange, strange...


    To do that kind of trickery you need to be at the C level. Ruby
    sometimes needs to create modules and classes that are not visible to
    your average Ruby application. In those cases it usually uses invalid
    names. (There's also the 'fatal' exception, for example.)

    Nevertheless, we can still get our hands on those special objects if we
    try hard enough:

    irb(main):002:0> result = nil; ObjectSpace.each_object { |obj| result =
    obj if obj.inspect == "NameError::message" }
    => 20510
    irb(main):003:0> result
    => NameError::message
    irb(main):004:0> result.method:)"!")
    => #<Method: NameError::message.!>

    We can even call it:

    irb(main):010:0> result.send:)"!", 1, 1, 1)
    => #<NameError::message:0x2b966d0>

    Nothing funky happens, though.

    BTW, that method and class probably shouldn't be documented.
     
    Florian Gross, Feb 16, 2005
    #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. Munnki
    Replies:
    2
    Views:
    539
    Munnki
    Dec 18, 2003
  2. Joe
    Replies:
    3
    Views:
    486
  3. Stimp

    CDONTS strangeness

    Stimp, May 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    425
    Tarren
    May 17, 2005
  4. Robert M. Gary

    Strangeness with Japanese, XML, Java

    Robert M. Gary, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    482
    Soren Kuula
    Apr 15, 2005
  5. Angus McIntyre

    Struts/JSP: logic.iterate strangeness

    Angus McIntyre, Oct 25, 2005, in forum: Java
    Replies:
    0
    Views:
    671
    Angus McIntyre
    Oct 25, 2005
Loading...

Share This Page