How can I invoke the 'include' in the class instance function

For same reason, I want to invoke the 'include' in the class instance
function.
The code like this:

···

******************************************************************************************
class QQ
module QQ_Elem
   def print_elem
     puts "elem"
   end
end

def test
   include QQ_Elem
   print_elem
   puts "test"
end
end

qq = QQ.new
qq.test
******************************************************************************************
But I got the error like this:
in `test': undefined method `include' for #<QQ:0x2bb5150>
(NoMethodError)

Is there anyone know the solution?
Thank you

Call it on the class instead, as in `self.class.include QQ_Elem`.

However, since it's only supposed to be called from within the class itself (not an instance of the class), it's marked as private. To circumvent this, call `self.class.send :include, QQ_Elem`.

···

On Nov 19, 2008, at 15:56, Jarod Zhu wrote:

But I got the error like this:
in `test': undefined method `include' for #<QQ:0x2bb5150>
(NoMethodError)

--
Name = "Mikael Høilund"; Email = Name.gsub %r/\s/,%#=?,#
*a=e=?=,!???,:??,?,Email.downcase![eval(%["\\%o\\%o"]%
[?**2+?o,?\\*2])]="o";Email.gsub! %%\%c%*3%a, %?%c? % ?@
def The(s)%%\%s.%%s+%.org\n.end; :Go and print The Email

Jarod Zhu wrote:

For same reason, I want to invoke the 'include' in the class instance
function.

class QQ
  module QQ_Elem
    def print_elem
      puts "elem"
    end
  end

  def test
    extend QQ_Elem # <-----------
    print_elem
    puts "test"
  end
end

qq = QQ.new
qq.test #=> elem
        # test

···

--
Posted via http://www.ruby-forum.com/\.