From: Gavin Sinclair Date: 2002-12-01T23:58:50+09:00 Subject: class << self (was Re: [FAQ] What do some of Ruby's symbols mean?) From: "Shannon Fang" > Hi, > On Sun, 1 Dec 2002 23:35:30 +0900 > ts wrote: > > > > If instance methods are stored in the class, where do you think that the > > class methods are stored ? > > I'm sorry I can't understand the purpose of your question. Is it related > to understanding class << object? The level I'm interested in is for > application developers, why they need to use <<, does it make their life > easier, or...? I did not consider to make the language developer's life > easier.. (sorry for being selfish :-p). > > Shannon You know what a class method is, right? class Example def Example.foo 19 end end Example.foo # -> 19 The same is achieved with class Example class << self def example 19 end end end I don't know why and I don't like it. I'm happy enough with singleton objects (but what's wrong with "def obj.meth"?): class << object def to_s "something unexpected" end end But I don't see why I should juggle Ruby meta-class models in my head just to define class methods. One advantage of the apparently beautiful "class << self" is that you can define several class methods at once without explicitly typing the class name, but I don't see what's gained here. To me it's obfuscated, and even when understood - or merely acknowledged - I think the notation is unintuitive. Hopefully I'm missing something and am about to have my fourth Ruby epiphany :) Gavin