# Include

**URL:** <https://rubytalk.org/t/include/22114>\
**Category:** ruby-talk\
**Created:** [3 November 2005 11:57 UTC](https://rubytalk.org/t/include/22114 "2005-11-03T11:57:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Fleck](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@Alexander\_Fleck](https://rubytalk.org/u/Alexander_Fleck)\
**Post date:** [3 November 2005 11:57 UTC](https://rubytalk.org/t/include/22114/1 "2005-11-03T11:57:09Z")

</div>

Hi,  
is the Ruby-'include' equal to a C++-'using' statement? Meant for namespace issues. Or does it have a bigger result?  
Thanks,  
Alex.

---

<div class="post-metadata">

**Author:** ![Christophe\_Grandsire](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Christophe\_Grandsire](https://rubytalk.org/u/Christophe_Grandsire)\
**Post date:** [3 November 2005 12:30 UTC](https://rubytalk.org/t/include/22114/2 "2005-11-03T12:30:35Z")

</div>

Selon Alexander Fleck \<Fleck@schleissheimer.de\>:

> Hi,  
> is the Ruby-'include' equal to a C++-'using' statement? Meant for namespace  
> issues. Or does it have a bigger result?  
> Thanks,  
> Alex.

"include" is used to mix in a module into a class. It has nothing to do with  
namespaces, but is rather a way to quickly add functionality to a class beyond  
what is given by its superclass without resorting to multiple inheritance.  
Mixins are in a way similar to Java interfaces, except that they contain  
fully-fledged methods, rather than just method signatures.

Note that Ruby 1.9 (the development version) now has the "using" keyword for  
namespaces too (check out:  
[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/6a732d353724f801/de6275a6a51b6bcd#de6275a6a51b6bcd\](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/6a732d353724f801/de6275a6a51b6bcd#de6275a6a51b6bcd%5C)).  
But since Ruby 1.9 is highly experimental, it might change before it becomes the  
stable Ruby2.

> **···**
>
> --  
> Christophe Grandsire.
> 
> [http://rainbow.conlang.free.fr](http://rainbow.conlang.free.fr)
> 
> It takes a straight mind to create a twisted conlang.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [3 November 2005 12:52 UTC](https://rubytalk.org/t/include/22114/3 "2005-11-03T12:52:12Z")

</div>

Christophe Grandsire wrote:

> Selon Alexander Fleck \<Fleck@schleissheimer.de\>:
> 
> > Hi,  
> > is the Ruby-'include' equal to a C++-'using' statement? Meant for  
> > namespace issues. Or does it have a bigger result?  
> > Thanks,  
> > Alex.
> 
> "include" is used to mix in a module into a class. It has nothing to  
> do with namespaces, but is rather a way to quickly add functionality  
> to a class beyond what is given by its superclass without resorting  
> to multiple inheritance=

Adding to that "extend" is more similar to "using". Using "extend" you  
can make some things (i.e. methods) from a module directly available.

Kind regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

---

<div class="post-metadata">

**Author:** ![Christophe\_Grandsire](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@Christophe\_Grandsire](https://rubytalk.org/u/Christophe_Grandsire)\
**Post date:** [3 November 2005 13:20 UTC](https://rubytalk.org/t/include/22114/4 "2005-11-03T13:20:31Z")

</div>

Selon Robert Klemme \<bob.news@gmx.net\>:

> Adding to that "extend" is more similar to "using". Using "extend" you  
> can make some things (i.e. methods) from a module directly available.

Indeed. And if you defined module methods in the module, you can even call them  
directly with the module name, without having to use "extend" to access them.

In other words, one can, and does, use modules for namespaces already. You just  
\*don't\* do that with "include", but rather without it 🙂 .

> **···**
>
> --  
> Christophe Grandsire.
> 
> [http://rainbow.conlang.free.fr](http://rainbow.conlang.free.fr)
> 
> It takes a straight mind to create a twisted conlang.
