Object#inspect's output

  • Thread starter Bertram Scharpf
  • Start date
B

Bertram Scharpf

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
 
J

Joel VanderWerf

Bertram said:
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.
 
B

Bertram Scharpf

Hi,

Am Donnerstag, 10. Mär 2005, 03:10:57 +0900 schrieb Joel VanderWerf:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top