From: Greg McIntyre Date: 2003-11-30T13:37:09+09:00 Subject: Re: class << x "Mark J. Reed" wrote: > On Sun, Nov 30, 2003 at 02:55:09PM +1100, Greg McIntyre wrote: > > I didn't ask what it does. I understand perfectly what "class << x" > > does and how it works and all about anonymous classes. > > I apologize; I was only trying to help, not impugn your knowledge, > And the reading "open x's class for modification" didn't sound like > you understood it, since "class << x" *doesn't* modify x's class, but > rather creates a new subclass just for x. > > > What I asked was, why is the syntax "class << x"? Is there a reason? > > Why "class << x"? > > It's designed to suggest that something very similar to > "class X < Y" (which defines a new class X as a subclass of Y) > is going on. The main differences are: > > 1. the new class has no name (so there's nothing on the left of > the <<) > > 2. the object on the right is not used directly as the > superclass, > even if it happens to be a class object; rather, its class > is used. > > 2. that object is modified such that it becomes an instance of > the new class (whereas class X < Y doesn't modify Y at all). I'm sorry, I was very curt. Thanks for spending time to answer me fully. That's something I love about ruby-talk and I'd hate to be unthankful of it. In all the time I've used Ruby, I've never recognised the similarity between "class X < Y" and "class << y". I suppose everybody else here thinks it's obvious. It does sort of kind of mean "open x's class", if you interpret x's class as it's _current_ class (possibly "type") and not the class object used to create x (which is the usual sense for "x's class"). I think in the past I've let some non-lingual section of my brain take over whenever I saw "class << x". :-) Everything goes fuzzy and I just kind of ignore the syntax and see the semantics. But it'd be nice if I understood it at a rational, logical level too. :-) -- Greg McIntyre ======[ greg@puyo.cjb.net ]===[ http://puyo.cjb.net ]===