"julius sirait" <[EMAIL PROTECTED]> writes:

> On 5/23/07, Widi Harsojo <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>
>>
>>
>> irb(main):071:0> 1.class
>> => Fixnum
>> irb(main):072:0> 121312312312.class
>> => Bignum
>> irb(main):073:0>
>>
>
> yoi. nah, kenapa untuk nilai yang sama, object_id nya sama. tebakan
> nya kan karna class method new gak ada. tapi kenapa untuk bignum,
> object_id nya beda padahal:
>
> irb(main):002:0> Fixnum.new
> NameError: undefined method `new' for Fixnum:Class
> from (irb):2
> irb(main):003:0> Bignum.new
> NameError: undefined method `new' for Bignum:Class
> from (irb):3
>
> --
> Julius Sirait

Itu implementation artifact untuk performance reason:


http://www.rubycentral.com/faq/rubyfaq-9.html
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
9.3 What is the difference between an immediate value and a reference?

Fixnum, true, nil, and false are implemented as immediate values. With
immediate values, variables hold the objects themselves, rather than
references to them.

Singleton methods cannot be defined for such objects. Two Fixnums of
the same value always represent the same object instance, so (for
example) instance variables for the Fixnum with the value "one" are
shared between all the "ones" is the system. This makes it impossible
to define a singleton method for just one of these. 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

YS.

Kirim email ke