From: "trans. (T. Onoma)" Date: 2004-11-15T10:30:10+09:00 Subject: Re: Dynamic define_method on class creation per module namespace On Sunday 14 November 2004 07:22 pm, nobu.nokada@softhome.net wrote: | What about this way? Though I don't think the name | class_method is proper... | | | module ClassMethods | def class_method(name, superclass = ::Object, method = | name.to_s.downcase, &definition) | c = Class.new(superclass, &definition) | define_method(method, &c.method(:new)) | module_function method | const_set(name, c) | end | end | | if $0 == __FILE__ | | module M | extend ClassMethods | | class_method(:A) do | def initialize ; puts "A" ; end | end | | class_method(:B) do | def initialize ; puts "B" ; end | end | end | | p M.a, M.b | end Right, that's one way to do it. Although that's manualizing things to the point that I think might be just as easy to go ahead and write out each method. Funny thing though, this really gives one pause in consideration of 'class' possibly being an actual method that one could tap into. T.