Trans wrote: > The issue, again, is that module class methods are not > "inherited" (for lack of a better word). In the past I've argued for > this, but it has been consistently argued down due to the extraneous > methods it would add to classes. However, it occurs to me that the IMHO the reason for this problem is that modules serve double duty as both mixins (instance methods) and namespaces (class methods). > core problem that I continually face for the lack of this, it simply > that I can't call super in a class level method and expect it to move > through included module methods. The reason this is such a problem, it > that it makes it very difficult to create an "inheriting variable". > This is the reason Facets contains inheritor.rb, but even that is > limited to only simple cases. The problem piqued my interest so despite my best attempts at self-control I wound up writing code for it :-/ class Module attr_accessor :class_methods_module def class_methods(&block) self.class_methods_module ||= begin mod = Module.new core = (class << self; self; end) prev = core.method(:included) core.send(:define_method, :included) do |into_class| prev.call(into_class) into_class.extend(mod) end mod end class_methods_module.class_eval(&block) end end class Class def class_methods(&block) instance_eval(&block) end end module M def a;"Ma";end class_methods do def b;"Mb";end end end class C include M def a;"Ca"+super;end class_methods do def b;"Cb"+super;end end end puts C.new.a #=> CaMa puts C.b #=> CbMb