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

**URL:** <https://www.ruby-forum.com/t/how-can-i-invoke-the-include-in-the-class-instance-function/153625>\
**Category:** Ruby\
**Created:** [November 19, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-can-i-invoke-the-include-in-the-class-instance-function/153625 "2008-11-19T16:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jarod\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Jarod\_Z](https://www.ruby-forum.com/u/Jarod_Z)\
**Post date:** [November 19, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-can-i-invoke-the-include-in-the-class-instance-function/153625/1 "2008-11-19T16:01:32Z")

</div>

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 solutione$B!)e(B  
Thank you

---

<div class="post-metadata">

**Author:** ![Jarod\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Jarod\_Z](https://www.ruby-forum.com/u/Jarod_Z)\
**Post date:** [November 19, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/how-can-i-invoke-the-include-in-the-class-instance-function/153625/2 "2008-11-19T16:27:24Z")

</div>

On Nov 19, 2008, at 15:56, Jarod Z. wrote:

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

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`.

---

<div class="post-metadata">

**Author:** ![Jarod\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Jarod\_Z](https://www.ruby-forum.com/u/Jarod_Z)\
**Post date:** [November 19, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/how-can-i-invoke-the-include-in-the-class-instance-function/153625/3 "2008-11-19T16:40:35Z")

</div>

Jarod Z. 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
