From: Daniel Schierbeck Date: 2006-05-18T22:11:29+09:00 Subject: Re: instance variables for Fixnum? Pascal Hurni wrote: > irb(main):001:0> 1.instance_variable_set(:@foo, 123) > => 123 > irb(main):002:0> 2.instance_variable_get(:@foo) > => nil > irb(main):003:0> 1.instance_variable_get(:@foo) > => 123 > > How is this possible? I thought Fixnum were 'value' type not real objects. > (in C they are VALUE which holds the value of the fixnum) Almost everything in Ruby is an object -- even Fixnums. There is only one `3' object -- it's not like a string, where two strings with the same content can very well be different objects. "foo".instance_variable_set(:@bar, "baz") "foo".instance_variable_get(:@bar) => ArgumentError 3.instance_variable_set(:@bar, "baz") 3.instance_variable_get(:@bar) => "baz" This is because Fixnums are immediates; so are symbols, btw. Daniel