Quoting http://www.rubygarden.org/faq/entry/show/83 :

"Fixnums, Symbols, 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."

~ ryan ~


On Dec 30, 2005, at 6:39 AM, Chris Pine wrote:

> On 12/30/05, Pete <pertl / gmx.org> wrote:
>> class Object
>>    def foo
>>      "foo"
>>    end
>>    class <<self
>>      def bar
>>        "bar"
>>      end
>>    end
>> end
>
> No, I meant giving the Fixnums themselves singleton methods, like  
> this:
>
> irb(main):001:0> a = 'hello'
> => "hello"
> irb(main):002:0> def a.hi
> irb(main):003:1>   'hi'
> irb(main):004:1> end
> => nil
> irb(main):005:0> a.hi
> => "hi"
> irb(main):006:0> b = 5
> => 5
> irb(main):007:0> def b.howdy
> irb(main):008:1>   'howdy'
> irb(main):009:1> end
> TypeError: can't define singleton method "howdy" for Fixnum
>         from (irb):7
> irb(main):010:0> :(  Why not??
>
>
> So I can do it for a string, but not a fixnum (or any other  
> immediate object).
>
> That's what surprised me.  You can have instance variables for 5, but
> not singleton methods for 5.  (Of course you can have methods for 5,
> but if 5 responds to it, then 6 does, too.)
>
> Cheers,
>
> Chris
>