# Creating and using modules

**URL:** <https://www.ruby-forum.com/t/creating-and-using-modules/63983>\
**Category:** Ruby\
**Created:** [June 20, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/creating-and-using-modules/63983 "2006-06-20T23:20:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [June 20, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/creating-and-using-modules/63983/1 "2006-06-20T23:20:17Z")

</div>

Hi,  
Newbie Question:

I’m trying to write a simple module/class, in it i’m trying to capture  
the repetitive, that i can reuse to make my life easier.

How do i setup this module, so i can make refernces to it?  
Where do i need to store the actual file?  
I would like to know how can i make references to this module?

if somebody can point me to the right direction, that’ll be very helpul.  
appreciate the help.  
Parvinder

---

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [June 21, 2006, 7:24am UTC](https://www.ruby-forum.com/t/creating-and-using-modules/63983/2 "2006-06-21T07:24:20Z")

</div>

Parv G wrote:

> if somebody can point me to the right direction, that’ll be very helpul.  
> appreciate the help.  
> Parvinder

Hi, I’m not sure I 100% understand what you want, but here goes:

You generally set up a class in a stand-alone rb-file. (“class MyClass;  
…; end” in myclass.rb, e.g.)  
Then, you either put it in one of the system library dirs, or below the  
dir that your project is stored in.  
Inside your program, you have a line like “require ‘myclass’”, then use  
it like any other class.

… Is this what you’re asking, did it answer your question?

---

<div class="post-metadata">

**Author:** ![parvg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bbe5ce/32.png) [@parvg](https://www.ruby-forum.com/u/parvg)\
**Post date:** [June 21, 2006, 7:27am UTC](https://www.ruby-forum.com/t/creating-and-using-modules/63983/3 "2006-06-21T07:27:29Z")

</div>

Parv G wrote:

> if somebody can point me to the right direction, that’ll be very helpul.  
> appreciate the help.  
> Parvinder

Well, you can store a module/class in with the rest of your code or as  
a separate file and use #require to bring it into your program.  
Generally these files are installed in a subdir of Ruby site\_ruby  
location. For instance, if you are using Debian linux:

/usr/local/lib/site\_ruby/1.8/mydir/myfile.rb

Then in your program:

require ‘mydir/myfile’

You should definitely read the PickAxe:

[http://www.rubycentral.com/book/index.html](http://www.rubycentral.com/book/index.html)

HTH,  
T.
