Ruby fixnums

Hello!

As I have understood Ruby fixnums are passed by value and
you can grab the value as an integer like:

VALUE foo;
int i = (int) (foo >> 1);

Is there any way to get an explicit reference of the
value of the fixnum in C, without allocating new space, or using
a new integer pointer?

I.e. what &RFLOAT(foo)->value does.

Regards,

···


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky

Elias Athanasopoulos wrote:

As I have understood Ruby fixnums are passed by value and
you can grab the value as an integer like:

VALUE foo;
int i = (int) (foo >> 1);

Is there any way to get an explicit reference of the
value of the fixnum in C, without allocating new space, or using
a new integer pointer?

I.e. what &RFLOAT(foo)->value does.

Well, you have to understand that the internal representation for Fixnum
values is different from most other objects in Ruby. If you create two
different Float objects with the same value, i.e.

x = 5.0
y = 5.0

then they are really two different objects, i.e.

x.id != y.id

but when you “create” two different Fixnum objects with the same value:

x = 5
y = 5

then they are references to the same object:

x.id == y.id is True

So the short answer is no, there’s no way to change the value of a
Fixnum object like you could with a Float, even from C code. A Fixnum is
what it is.

Thanks for the detailed reply.

Regards,

···

On Wed, Feb 11, 2004 at 01:15:03AM +0900, Lyle Johnson wrote:

So the short answer is no, there’s no way to change the value of a
Fixnum object like you could with a Float, even from C code. A Fixnum is
what it is.


University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky