ri strangeness

M

martinus

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
 
F

Florian Gross

martinus said:
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.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top