[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] Article: Seeing Metaclasses Clearly

why the lucky stiff

4/18/2005 6:50:00 AM

I've written a very nuts+bolts article on metaclasses (aka virtual
classes or metaobjects), since they still lurk under a shroud of fear
and enigma.

<http://whytheluckystiff.net/articles/seeingMetaclassesClearl...

I'm hoping this will help uncover the truth. If anything is unclear,
please report it. Shed a light.

Sharkin',

_why



94 Answers

Sascha Ebach

4/18/2005 9:35:00 AM

0

why the lucky stiff wrote:
> I've written a very nuts+bolts article on metaclasses (aka virtual
> classes or metaobjects), since they still lurk under a shroud of fear
> and enigma.
>
> <http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
>
> I'm hoping this will help uncover the truth. If anything is unclear,
> please report it. Shed a light.

Very nice and thanks,

would you mind using a print stylesheet so the article can be nicely
printed out?

Sascha Ebach


dblack

4/18/2005 11:48:00 AM

0

Florian Groß

4/18/2005 12:34:00 PM

0

why the lucky stiff wrote:

> <http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
>
> I'm hoping this will help uncover the truth. If anything is unclear,
> please report it. Shed a light.

Nice article, but I disagree in the point that @@vars are simpler than
class instance variables. Class instance variables have odd semantics in
the current Ruby which means that they will probably do some detail
different than you expect.

I've found that sticking to class instance variables (and thus keeping
things simple -- why do we need another type of variables again?) helps
in making code easier to understand.

Perhaps you should display both sides of this in the article.



Gavin Kistner

4/18/2005 12:46:00 PM

0

On Apr 18, 2005, at 6:33 AM, Florian Groß wrote:
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics
> in the current Ruby which means that they will probably do some detail
> different than you expect.

But you have to do:

class Foo
@var1 = []
@var2 = {}
class << self
attr_accessor :var1, :var2
end
end

to get reasonable access to those class instance variables inside an
instance method, and even then you have to do self.class.var1


Once you 'get it' it's not TERRIBLY difficult, but I would say that the
above is more than enough justification for calling @@foo simpler.
Simpler, but also confusing in the inherited-class cases. (So confusing
that I still don't fully grok what specifically occurs that makes @@foo
unusable, and when it occurs. I'm still grasping at the fringes of the
tablecloth.)




Robert Klemme

4/18/2005 12:48:00 PM

0


"Florian Groß" <florgro@gmail.com> schrieb im Newsbeitrag
news:d4093s$dml$1@sea.gmane.org...
> why the lucky stiff wrote:
>
> > <http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
> >
> > I'm hoping this will help uncover the truth. If anything is unclear,
> > please report it. Shed a light.
>
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics in
> the current Ruby which means that they will probably do some detail
> different than you expect.
>
> I've found that sticking to class instance variables (and thus keeping
> things simple -- why do we need another type of variables again?) helps
> in making code easier to understand.

+1

> Perhaps you should display both sides of this in the article.

Yeah, I missed that, too. In fact, the article seems to discourage class
instance variable usage...

Kind regards

robert

Karl von Laudermann

4/18/2005 12:49:00 PM

0

why the lucky stiff wrote:
> I've written a very nuts+bolts article on metaclasses (aka virtual
> classes or metaobjects), since they still lurk under a shroud of fear

> and enigma.
>
> <http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
>
> I'm hoping this will help uncover the truth. If anything is unclear,

> please report it. Shed a light.

Noticed a small mistake; At one point, you refer to the at-sign (@) as
an ampersand. Other than that... the article went way over my head and
twisted my poor brain into knots. :-( I think I'll need to re-read
chapter 24 of Pickaxe 2 immediately before reading this article.

why the lucky stiff

4/18/2005 1:43:00 PM

0

Florian Groß wrote:
> Nice article, but I disagree in the point that @@vars are simpler than
> class instance variables. Class instance variables have odd semantics in
> the current Ruby which means that they will probably do some detail
> different than you expect.

You're right. I'm oversimplifying this. I need to discuss the
metaclass/inheritance thing a bit more.

_why



Curt Hibbs

4/18/2005 1:48:00 PM

0

David A. Black wrote:
> Hi --
>
> On Mon, 18 Apr 2005, why the lucky stiff wrote:
>
>> I've written a very nuts+bolts article on metaclasses (aka virtual
>> classes or
>> metaobjects), since they still lurk under a shroud of fear and enigma.
>>
>> <http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
>>
>> I'm hoping this will help uncover the truth. If anything is unclear,
>> please
>> report it. Shed a light.
>
>
> For some reason the first 1/8 inch or so on the left are cut off on my
> browser. I don't know whether it's a CSS thing or a browser thing
> (Netscape 6). So "methods" comes out as "thods", etc.

Also, in Firefox 1.0 on Windows XP, when I try to print it, it only
prints the first page. If I use MS Internet Explorer, it prints just fine.

Curt


why the lucky stiff

4/18/2005 2:01:00 PM

0

David A. Black wrote:
> The tutorial itself looks good, though the terminology in this area
> continues to be a problem. My understanding is that the most general
> term is "singleton class", and that "metaclass" is a special term for
> singleton class of a Class object. (See Pickaxe, 2nd ed., p. 382.)
> So, for example, I would rename your Object#metaclass method
> #singleton_class, since it applies to all objects (as per RCR 231).

Sure, I'm aware that "virtual class" is the generic term, while Matz has
also used "singleton class" and "meta-object" to describe these classes
used in tandem with an RObject.

I only use the term "metaclass" because it is the term predominantly
used in the PickAxe II. While Dave does interchangibly use "virtual
class" and "singleton class", the only term he uses to generically refer
to the construct is "metaclass".

And I really need to be able to wrap these up in a single word, whilst
still jiving with the PickAxe.

_why




Mike Woodhouse

4/18/2005 2:15:00 PM

0


Karl von Laudermann wrote:
> why the lucky stiff wrote:
> > I've written a very nuts+bolts article on metaclasses (aka virtual
> > classes or metaobjects), since they still lurk under a shroud of
fear
>
> > and enigma.
> >
> >
<http://whytheluckystiff.net/articles/seeingMetaclassesClearl...
> >
> > I'm hoping this will help uncover the truth. If anything is
unclear,
>
> > please report it. Shed a light.
>
> Noticed a small mistake; At one point, you refer to the at-sign (@)
as
> an ampersand. Other than that... the article went way over my head
and
> twisted my poor brain into knots. :-( I think I'll need to re-read
> chapter 24 of Pickaxe 2 immediately before reading this article.

Glad I'm not the only one who has to go back to the books! (I did spot
the "ampersand" thing, though).