instance_eval problem

B

bitmox

Hi,

I' ve got problem with instance_eval.

I tried the following with irb:x
=> nilTypeError: (eval):1:in `irb_binding': no class/module to add method
from (irb):31

Why does the instance_eval not work for the Fixnum?

Best regards,
Thomas
 
S

Stefano Crocco

Alle Wednesday 20 February 2008, bitmox ha scritto:
Hi,

I' ve got problem with instance_eval.

I tried the following with irb:

=> "3"


=> nil


x
=> nil


=> 3


TypeError: (eval):1:in `irb_binding': no class/module to add method
from (irb):31

Why does the instance_eval not work for the Fixnum?

Best regards,
Thomas

instance_eval works for Fixnums. For example:

(-1).instance_eval("abs")
=> 1

The problem is that you can't define singleton methods for Fixnums (this is
also true for Floats and Bignums):

x = 1
def x.a
end
=> TypeError: can't define singleton method "a" for Fixnum

Stefano
 
B

bitmox

Alle Wednesday 20 February 2008, bitmox ha scritto:
Hi Stefano,

thank you for your hint.
I checked the documentation for Fixnum meanwhile. There is described,
that is impossible to a singleton method.

Thomas
 

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
474,284
Messages
2,571,411
Members
48,103
Latest member
MadieDeitz

Latest Threads

Top