Why there are always fixed object_id s for Boolean objects?

If you find the below test,you would see that, `object_id`s are always
same for the three objects - `true`,`false` and `nil`.

Why for these objects `object_id` s are not allocated in run time?

true.object_id

=> 2

false.object_id

=> 0

nil.object_id

=> 4

'a'.object_id

=> 17515344

nil.object_id

=> 4

'a'.object_id

=> 18433428

false.object_id

=> 0

'a'.object_id

=> 18454176

true.object_id

=> 2

···

--
Posted via http://www.ruby-forum.com/\.

Because they refers to constants created when the VM arise, always.

nil.==(NIL)
true.==(TRUE)
false.==(FALSE)

Perhaps could be a better explanation.

···

--
Posted via http://www.ruby-forum.com/.

As usual

John

···

On Wed, Mar 6, 2013 at 9:37 AM, Kumar R. <lists@ruby-forum.com> wrote:

If you find the below test,you would see that, `object_id`s are always
same for the three objects - `true`,`false` and `nil`.

Why for these objects `object_id` s are not allocated in run time?

>> true.object_id
=> 2
>> false.object_id
=> 0
>> nil.object_id
=> 4
>> 'a'.object_id
=> 17515344
>> nil.object_id
=> 4
>> 'a'.object_id
=> 18433428
>> false.object_id
=> 0
>> 'a'.object_id
=> 18454176
>> true.object_id
=> 2
>>

--
Posted via http://www.ruby-forum.com/\.

object_ids are also the same for Fixnum objects

its a feature not a bug

PS: but they can differ between different ruby versions

(in 2.0 little floats are also have fixed ids)

···

--
Posted via http://www.ruby-forum.com/.