From: Mark Sparshatt Date: 2004-06-26T02:57:00+09:00 Subject: Re: I am confused with Value Type Objects Sam Sungshik Kong wrote: >Hello! > >In ruby, every object is reference type except for FixNum, NilClass, >TrueClass, FalseClass. >Let's consider FixNum only. > >According to http://www.rubygarden.org/ruby?GCAndMemoryManagement, FixNum >takes only 4 bytes (on 32-bit machines). >Is it true? >If so, doesn't it have any other information except for the value itself? >How does ruby know that a FixNum is actually a FixNum instead of a reference >to an object when it doesn't have any information about the type? > >I'm from C# background. >In C# (actually dotnet framework), values types are structures not just a >simple value. > >Could somebody resolve my confusion? > > > Ruby checks the least significant bit of the value. If this is set then the value is a direct value such as a fixnum, otherwise it's a reference to an object. When Ruby is constructing a fixnum it left shifts the number one place then sets the LSB. HTH -- Mark Sparshatt