From: Uncutstone Wu Date: 2006-09-18T12:31:52+09:00 Subject: A idea about Ruby module, can we degrade a class to a module To naturally represent following kind of relationship in Ruby code, I think, if we can degrade a class to a module, it will be posssible. For example, we have a Person class, a Man class ,and a Teacher class. Man inherits from Person. And a Man object may also act as a teacher 。Usually, we can implement this relationship as follows: class Person end class Teacher end class Man < Person set_teacher(a_teacher) @teacher = a_teacher end end In this implementation, a Man object is a delegator to a Teacher object. To call Teacher methods from a Man object , we need lots of delegate method. It’s unconvenient. But how about if Ruby provide a degradation mechanism, then we can degrade a class to a module, then we can include the degraded class into another class. The code will become as follows: class Person end class Teacher end degrade_to_module Teacher # or something else, this is imagined by me . class Man < Person include Teacher end Or something like this class Person end class Teacher end degrade_to_module Teacher # or something else, this is imagined by me . Class Man < Person End M = Man.new m.externd(Teacher) Dose this make sense? Thanks. Best regards uncutstone -- Posted via http://www.ruby-forum.com/.