# "using namespace" equivalent?

**URL:** <https://rubytalk.org/t/using-namespace-equivalent/25908>\
**Category:** ruby-talk\
**Created:** [19 March 2006 14:28 UTC](https://rubytalk.org/t/using-namespace-equivalent/25908 "2006-03-19T14:28:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![killy-kun](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@killy-kun](https://rubytalk.org/u/killy-kun)\
**Post date:** [19 March 2006 14:28 UTC](https://rubytalk.org/t/using-namespace-equivalent/25908/1 "2006-03-19T14:28:49Z")

</div>

I would like to know if there is in ruby an equivalent to the c++ instruction "using namespace" (in order not to have to prefix things by there namespace when needed).

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [19 March 2006 15:59 UTC](https://rubytalk.org/t/using-namespace-equivalent/25908/2 "2006-03-19T15:59:16Z")

</div>

> I would like to know if there is in ruby an equivalent to the c++ instruction "using namespace" (in order not to have to prefix things by there namespace when needed).

Well, if we are talking about a module, you might be able to include it:

\>\> module Namespace  
\>\> extend self  
\>\> def some\_method  
\>\> puts "Hello!"  
\>\> end  
\>\> end  
=\> nil  
\>\> Namespace::some\_method  
Hello!  
=\> nil  
\>\> include Namespace  
=\> Object  
\>\> some\_method  
Hello!  
=\> nil

Hope that helps.

James Edward Gray II

> **···**
>
> On Mar 19, 2006, at 8:28 AM, killy-kun wrote:

---

<div class="post-metadata">

**Author:** ![killy-kun](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@killy-kun](https://rubytalk.org/u/killy-kun)\
**Post date:** [19 March 2006 18:03 UTC](https://rubytalk.org/t/using-namespace-equivalent/25908/3 "2006-03-19T18:03:49Z")

</div>

James Edward Gray II wrote:

> **···**
>
> > On Mar 19, 2006, at 8:28 AM, killy-kun wrote:
> > 
> > > I would like to know if there is in ruby an equivalent to the c++ instruction "using namespace" (in order not to have to prefix things by there namespace when needed).
> > 
> > Well, if we are talking about a module, you might be able to include it:
> > 
> > \>\> module Namespace  
> > \>\> extend self  
> > \>\> def some\_method  
> > \>\> puts "Hello!"  
> > \>\> end  
> > \>\> end  
> > =\> nil  
> > \>\> Namespace::some\_method  
> > Hello!  
> > =\> nil  
> > \>\> include Namespace  
> > =\> Object  
> > \>\> some\_method  
> > Hello!  
> > =\> nil
> > 
> > Hope that helps.
> > 
> > James Edward Gray II
> 
> Thank you very much !!  
> That's exactely what I was looking for.  
> (I was using the "require" instruction, and I thought the "include" instruction was quite similar, that is why I didn't try it...)
