Hi -- On Wed, 15 Mar 2006, gwtmp01 / mac.com wrote: > > On Mar 13, 2006, at 12:38 PM, Trans wrote: >> Rather then using a specific method for accessing the >> singleton/eigennclass, could we just use an alternate to dot-notation. >> I.e. Instead of 'x.eigenclass.foo' either 'x:foo' or 'x!foo', or >> somthing like that. > > When I first encountered singleton class notation in Ruby: > > class <<obj; end > > I thought of '<<' in this situation as a prefix operator on the object. I know it sounds minor but I think with the space it's much clearer that this isn't the case: class << obj I've always thought of this as sort of pulling the class out of the object, or something. > I suppose you hack the parser to understand that but I'm guessing it > would really tangle up the grammar. In any case, the parser doesn't treat > the text after the 'class' keyword as an expression. You can't substitute > '<<obj' for an expression that evaluates to an eigenclass. I always thought > that was strange. Why doesn't the parser just look for an expression that > evaluates to a class object? The superclass can be specified by an > expression, > why can't the 'regular' class be handled in the same way? > > In any case, I think that '<<obj' is seems out of place relative > to the rest of Ruby's syntax. > > I'd prefer a method to access the singleton class object: > > obj.singleton_class > > is OK but I tend to like more terse names: > > obj.sclass > > If we had this, I would expect: > > class obj.sclass > end > > to do the obvious thing and open up obj's singleton class. I'm certainly a Kernel#s[ingleton_]class advocate, but I don't think it's obvious that this change in the behavior of the class keyword would follow, since: class some_class_in_a_variable doesn't work. I don't know the reasoning behind it. David -- David A. Black (dblack / wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black