From: polypus Date: 2006-05-04T06:36:08+09:00 Subject: klass.include vs instance.extend question i want a few instance methods to be automatically defined for the user without any explicit coding on their part. in the below distillation of my code, i have two options (labelled), my question is whether one option is better in any way than the other, and why one would prefer one over the other. my suspicion is that option 1 is more space efficient, and option 2 more time efficient, is that correct? also i should note that for people to use my module M they must call (for other reasons) extend, foo, and init_m in the extended class regardless of which option i finally choose. also the method init_m must be defined in the manner below (define_method) regardless of the option i choose, also for other reasons. and so you should not take any of their having to be there or not into account in your assesment. thanks many. module InstanceMethods # instance methods in here end module M # option 1 def self.extend_object klass klass.class_eval 'include InstanceMethods' super end # option 2 def foo define_method :init_m do self.extend InstanceMethods end end end class X extend M foo def intialize init_m end end -- Posted via http://www.ruby-forum.com/.