[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Object#inspect's output

Bertram Scharpf

3/9/2005 5:55:00 PM

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-...


2 Answers

Joel VanderWerf

3/9/2005 6:11:00 PM

0

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.


Bertram Scharpf

3/9/2005 11:33:00 PM

0

Hi,

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


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...