class Object
   def foo
     "foo"
   end
   class <<self
     def bar
       "bar"
     end
   end
end

examples:

"Some string".foo
-> "foo"

Bignum.bar
-> "bar



On Fri, 30 Dec 2005 09:57:09 +0100, Chris Pine <chris / pine.fm> wrote:

> On 12/30/05, gwtmp01 / mac.com <gwtmp01 / mac.com> wrote:
>> Am I the only person with their jaw on the ground?
>
> When I discovered this, what surprised me was not so much that you
> could do this, but that can do this _even_though_ you can't give them
> singleton methods (or access their singleton classes).
>
> I just assumed the reason was because the singleton classes are stored
> in some structure that immediate values don't have, but that instance
> variables are stored separately in some other way.  (I never looked at
> the interpreter source to verify this, though.)
>
> So the question in my mind:  Is there a reason we couldn't do that
> with ints, too?
>
> Chris
>