From: Joel VanderWerf Date: 2003-11-30T17:02:41+09:00 Subject: Re: class << x The 'class << x' notation has some weaknesses: * It looks a bit like a heredoc, but there is no analogy. * '<<' does not have any other role as an operator or special form associated with singleton classes. * '<<' suggests an append or shift operation, or perhaps a "much less than" comparison, or even some kind of bracket ('<>') notation. * It looks too much like 'class Y < x' in which the new class Y is less than x in the ancestral sense. However, the analogy is false--there is no class below x. * How do you read it? "class under x"? "class singleton of x"? It has bothered me for the last 3 years, but I simply accept it as an idiom and get on with life. We don't always have to construct meaning for the symbols we push around. Still, I'd feel better if there were some method on objects that returned the singleton class and you could use that in a class definition, something like this: def singleton(x); class << x; self; end; end x = [0,1,2,3] # class singleton(x); end # parse error! singleton(x).class_eval do def last_elt; at(-1); end end p x.last_elt # ==> 3 But this is a poor workaround, since do..end and class..end have different scoping rules.