From: gwtmp01@... Date: 2005-12-11T13:05:09+09:00 Subject: Re: About class methods On Dec 10, 2005, at 8:34 PM, jonathan wrote: > Hmm. Ok, so there really is no singleton class for Myclass? In other > words, must the singleton always be associated with an instance and > not > a class? In Ruby, a class *is* an instance. Specifically, a class is an instance of the class Class. So, yes, you can reference the singleton object of a class: class < Yea. That is cool, but can you still do something like this: > > class Myclass > end > > def extend_class( some_class ) > code = %{ class #{some_class.class}_extension < #{some_class.class} > def new_method1 > end > ... > end } > eval( code ) > > extend_class( Myclass ) > x = Myclass_extension.new > x.new_method1 > y = Myclass_extension.new > y.new_method1 I'm not sure what you are getting at here. Myclass.class is the particular object Class. Because all class objects are instances of Class. #{some_class.class}_extension ends up being the string Class_extension because Class.to_s is the string 'Class'. If you want to subclass and add methods just do it: class Myclass end class Subclass < Myclass def new_method1 end end x = Subclass.new y = Subclass.new x.new_method1 y.new_method1