Extending when running IRB

Hi,

I run irb.

Then I input something like:

“ajklasfjlasfkjlafs”

IRB then responds with this:

NameError: undefined local variable or method `ajklasfjlasfkjlafs’ for
#<Object:0xb758c958 @x="">
from (irb):1

Which is correct behaviour.

What I now want to do is do a specific action BEFORE this error
happens.

Specifically, I want to load a class there BEFORE the NameError is
registered. That class will process the input further, and only if
it can not act on that input, should it give control to NameError.
(Otherwise, no NameError should be raised.)

What would be ways to do this?
I was thinking I could extend Object at runtime, if I would be using
Irb,
and load my class.

On Sun, Jan 22, 2012 at 11:04 PM, Marc H. [email protected]
wrote:

NameError: undefined local variable or method `ajklasfjlasfkjlafs’ for
#<Object:0xb758c958 @x=“”>
from (irb):1

Which is correct behaviour.

Do you want that string to be a local variable, method or constant?

What I now want to do is do a specific action BEFORE this error
happens.

Could be tricky because that might be in the compilation process (i.e.
somewhere in eval). But you might get away to wrap IRB’s line
processing, catch NameError, detect the variable name and act on this.

Specifically, I want to load a class there BEFORE the NameError is
registered. That class will process the input further, and only if
it can not act on that input, should it give control to NameError.
(Otherwise, no NameError should be raised.)

What would be ways to do this?
I was thinking I could extend Object at runtime, if I would be using
Irb,
and load my class.

You can add code to ~/.irbrc to define any class or load any Ruby
script.

Kind regards

robert