From: Gavin Sinclair Date: 2003-11-30T15:25:13+09:00 Subject: Re: class << x On Sunday, November 30, 2003, 2:57:07 PM, Greg wrote: > I didn't ask what it does. I understand perfectly what "class << x" does > and how it works and all about anonymous classes. What I asked was, why > is the syntax "class << x"? Is there a reason? Why "class << x"? When I was a newbie, I accepted o = Object.new class << o ... end perfectly well. I didn't have a way to "read" it, but I was happy with the syntax. It took a bit of mental gymnastics to understand class A class << self ... end end but I wouldn't sacrifice the unity of concept (a class is an object) for anything. To summarise: I've never been put out by the syntax that Ruby has to offer in this regard, and see no need for an alternative. The alternative you offer is invalid, because it treads on a valid concept in Ruby: classes within classes. class A class A puts self.to_s # "A::A" end end And the other thing you offer I find confusing: b = B.new class b.class def f ... end end I expected this to add a method to B (the class, not the object), but it was a syntax error. Why? b.class evaluates to B, and class B is valid. Oh well. Anyway, I hope I've demonstrated why it doesn't communicate with me what you want it to. To summarise, again. The issues that you raise are certainly things that need to be explained to newbies quite often. Normally, that would reasonably be seen as a problem with the language. In this case, however, I think the language has it right and everybody needs to adjust their thinking. Cheers, Gavin