From: Daniel Brockman Date: 2005-07-02T09:32:38+09:00 Subject: Re: How and where Fixnum are created Eustaquio, All Ruby objects are aligned on four-byte boundaries in memory, so all pointers are divisible by four. The rest of the pointer values are used to store immediate values such as fixnums. (This is a pretty standard way to store immediate values in dynamic languages that lack static typing.) So when you say this, foo = Object.new an object is created and its address (which will be divisible by four) is stored in `foo'. But when you say this, bar = 42 the integer 42 is doubled, increased by one, and the resulting value is stored directly in `bar'. That's how Ruby stores fixnums. Later, when you say this, foo.moomin Ruby sees that `foo' is divisible by four and so must be a pointer to an object, and a regular method call is made. But when you say this, bar.snufkin it sees that `bar' contains 85, which is an odd integer --- not divisible by four. The oddness means that `bar' is an immediate Fixnum, so Ruby converts the value to its real meaning by subtracting one and halving it, giving 42. Then the method `snufkin' is looked up in the Fixnum class and invoked with `self' bound to 42. Okay, I realize that this explanation turned out pretty confusing. For more information, you might search for ``ruby immediate values.'' I hope this helps at least a bit, -- Daniel Brockman