From: Robert Klemme Date: 2009-12-30T05:16:56+09:00 Subject: Re: Using #include at the instance level? 2009/12/29 Intransition : > This is really becoming annoying. I can't even do it via a dynamic > class definitions either. > >  module M >    def m1; "m1"; end >    module N >      def self.n1; "n1"; end >    end >  end > >  class X >    class << self >      alias _new new >      def new(&block) >        klass = Class.new(self) >        klass.class_eval(&block) >        klass._new >      end >    end > >    def m ; m1 ; end >    def n ; N.n1 ; end >  end > >  x = X.new do >    include M >  end > >  p x.m >  p x.n   #=> uninitialized constant X::N (NameError) > > Did constant lookup change between 1.8.6 and 1.8.7? Seems to me this > used to be possible, and I find it unacceptable that normal constant > lookup would not apply to dynamic class definitions, let alone the > singleton classes. AFAIK it hasn't changed and your code could never work in any version of Ruby because the const lookup in method #n is done _statically_. Apart from that you are defining method X#n and not #n so the lookup could never work if you would instantiate X. Also, on a more abstract level: it is at least a bit odd to define class X which can only ever work if you make sure you include "N" (whichever way). I believe you haven't yet fully analyzed the problem you want to solve. I suggest to put it to sleep for a while and then get back later to it. I can't help you any more because to me it is not clear what you are trying to achieve. So far we only went through technical issues but the problem you are trying to solve isn't cleat to me yet. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/