Hi,
I want to understand thoroughly how singleton objects are
implemented. I try this:
class C ; end
puts C.inspect # => C
puts class <<C ; self ; end.inspect # => #<Class:C>
Can someone give me a hint what's the difference between the
both objects inspected? Thanks very much in advance.
Bertram
···
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Bertram Scharpf wrote:
Hi,
I want to understand thoroughly how singleton objects are
implemented. I try this:
class C ; end
puts C.inspect # => C
puts class <<C ; self ; end.inspect # => #<Class:C>
Can someone give me a hint what's the difference between the
both objects inspected? Thanks very much in advance.
The second object is the metaclass of C. There's a good explanation of metaclasses in the PickAxe book.
Hi,
Bertram Scharpf wrote:
>I want to understand thoroughly how singleton objects are
>implemented. I try this:
>
> class C ; end
>
> puts C.inspect # => C
> puts class <<C ; self ; end.inspect # => #<Class:C>
The second object is the metaclass of C. There's a good explanation of
metaclasses in the PickAxe book.
Ah, I see.
class C ; def self.clsmeth() end end
# => nil
class <<C ; self ; end.instance_methods - Class.methods
# => ["clsmeth"]
Thanks.
Bertram
···
Am Donnerstag, 10. Mär 2005, 03:10:57 +0900 schrieb Joel VanderWerf:
--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de