From: "David A. Black" Date: 2007-11-09T08:32:59+09:00 Subject: Re: 'Class.inherited' v. 'inherited' syntax inside Class Hi -- On Fri, 9 Nov 2007, 7stud -- wrote: > How come when you redefine the inherited method in Class, you don't use > the 'class method' syntax? This doesn't work: > > class Class > def Class.inherited(class_obj) > puts class_obj > puts > end > end > > > Instead, you have to write: > > class Class > def inherited(class_obj) > puts class_obj > puts > > end > end > > Yet, in pickaxe2 on p. 445, the book lists inherited as a class method > of Class. The term "class method" can refer to either of two things: an instance method of Class, or a singleton method of a given class. When you call them, the technique is the same: class Class def an_instance_method puts "I'm an instance method of Class" end end class C def a_singleton_method puts "I'm a singleton method of C" end end C.an_instance_method C.a_singleton_method So... when you do this: class Class def inherited ... you're defining an instance method called "inherited", and all instances of Class -- that is, all classes -- will have that method. When you define Class.inherited, you're defining a singleton method on Class. The only thing that would be affected by that would be if you created a subclass of Class -- but Ruby doesn't permit that. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!