# Importing module to local namespace

**URL:** <https://www.ruby-forum.com/t/importing-module-to-local-namespace/123310>\
**Category:** Ruby\
**Created:** [December 16, 2007, 7:39am UTC](https://www.ruby-forum.com/t/importing-module-to-local-namespace/123310 "2007-12-16T07:39:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![neko18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a88e4f/32.png) [@neko18](https://www.ruby-forum.com/u/neko18)\
**Post date:** [December 16, 2007, 7:39am UTC](https://www.ruby-forum.com/t/importing-module-to-local-namespace/123310/1 "2007-12-16T07:39:21Z")

</div>

I’m trying to do something like:

##### 

# File: blah.rb

module Blah  
def something  
puts “something”  
end  
def another  
puts “another”  
end  
end

##### 

# File: blahtest.rb

require ‘blah’  
Blah.something #-\> “something”  
Blah.another #-\> “another”  
import\_to\_local Blah  
something #-\> “something”  
another #-\> “another”

Coming from a Python background, I’m looking to do the approximate  
equivalent of “from Blah import \*”

---

<div class="post-metadata">

**Author:** ![neko18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a88e4f/32.png) [@neko18](https://www.ruby-forum.com/u/neko18)\
**Post date:** [December 16, 2007, 7:46am UTC](https://www.ruby-forum.com/t/importing-module-to-local-namespace/123310/2 "2007-12-16T07:46:09Z")

</div>

> ##### 
> 
> # File: blah.rb
> 
> module Blah  
> def something  
> puts “something”  
> end  
> def another  
> puts “another”  
> end  
> end

I meant:

##### 

# File: blah.rb

module Blah  
def Blah.something  
puts “something”  
end  
def Blah.another  
puts “another”  
end  
end

---

<div class="post-metadata">

**Author:** ![neko18](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/a88e4f/32.png) [@neko18](https://www.ruby-forum.com/u/neko18)\
**Post date:** [December 16, 2007, 8:40am UTC](https://www.ruby-forum.com/t/importing-module-to-local-namespace/123310/3 "2007-12-16T08:40:49Z")

</div>

For the easiest thing, just stick with your first example of using  
instance methods, and then “include Blah”. Why it works and what is  
doing probably won’t really apparent, though.

You want to look into Mixins (and the keywords extend and include),  
but you also want to get a good understanding of what local (self)  
means in this context, because that will make which incantation you  
want much easier to figure out, and rarely are you going to want to do  
a bare include Foo or extend Foo on the top level context like that.

You should read the pickaxe as a bare minimum. The section on Modules  
is a start: [http://www.rubycentral.com/pickaxe/tut\_modules.html](http://www.rubycentral.com/pickaxe/tut_modules.html) Jay  
Fields has a good intro, though, too that might answer your question  
more directly:  
[Jay Fields' Thoughts: Ruby extend and include](http://blog.jayfields.com/2006/05/ruby-extend-and-include.html)  
Then you can start looking into the ClassMethods include idioms and  
other fanciness.
