From: Gregory Seidman Date: 2006-04-11T23:29:32+09:00 Subject: Re: Adding in class attribute with a Module On Tue, Apr 11, 2006 at 06:19:23AM +0900, TRANS wrote: } > Does this count as ugly meta-programming? } > } > module M } > def self.included(klass) } > class << klass } > attr_accessor :m } > end } > end } > end } } Yep. That's Ugly Hack #1. What wrong with Ugly Hack #1, you ask? } } module N } include M } end } } class C } include N } end } } C.m } NoMethodError: undefined method `m' for C:Class Yep, that's an issue. Well, you can do this: module M OnIncludeProc = lambda do |klass| if klass.class == Module def klass.included(k) OnIncludeProc.call(k) end else class << klass attr_accessor :m end end end OnIncludeProc.call(self) end Yes, it's uglier. Yes, it conflicts with other #included tricks with modules that include the module. It does work, though. } T. --Greg