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