From: Rick DeNatale Date: 2007-06-03T10:48:36+09:00 Subject: Re: so lost on singleton, metaclass and virtual class On 6/2/07, Dorren wrote: > Q1: in pick axe book page 364, it talks about metaclass should be a > singleton class. but when I run the following code, class's object_id > are the same for all instance, but the metaclass object_id are > different for each object instance, is the code wrong or what? Here we are talking about singleton classes used to provide instance specific behavior. Singleton here means that the singleton class has only one instance. So each instance which needs one, has its own singleton class. > Q2: from pick axe book 364-367, it used singleton, metaclass, and > virtual class definition interchangeably. are they all the same thing > or not? No they arent. Singleton classes are classes which are marked internally with a flag bit called FL_SINGLETON. You don't normally see these classes unless you use the class < Q3: from page 365, > "To handle per-object attributes, Ruby provides a classlike some- > thing for each object that is sometimes called a singleton class." > if runtime create something new for EACH object, how can it be called > singleton? This is really the same question as Q1. This relates to an earlier thread here from last week. I just converted my reply to that thread to a blog entry at: http://talklikeaduck.denhaven2.com/articles/2007/06/02/chain-chain-chain Which might make some of this more understandable. HTH -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/