# Including Module

**URL:** <https://www.ruby-forum.com/t/including-module/167672>\
**Category:** Ruby\
**Created:** [May 11, 2009, 10:42am UTC](https://www.ruby-forum.com/t/including-module/167672 "2009-05-11T10:42:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thangappan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@thangappan](https://www.ruby-forum.com/u/thangappan)\
**Post date:** [May 11, 2009, 10:42am UTC](https://www.ruby-forum.com/t/including-module/167672/1 "2009-05-11T10:42:31Z")

</div>

I am new to Ruby.  
Is there any way to include the module in normal ruby file?

For an example,

Test.rb

Class Test.rb  
…  
end

testing.rb

object = Test.new # It tells error.

---

<div class="post-metadata">

**Author:** ![thangappan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@thangappan](https://www.ruby-forum.com/u/thangappan)\
**Post date:** [May 11, 2009, 11:09am UTC](https://www.ruby-forum.com/t/including-module/167672/2 "2009-05-11T11:09:43Z")

</div>

Thangappan Mohana sundaram wrote:

> I am new to Ruby.  
> Is there any way to include the module in normal ruby file?
> 
> For an example,
> 
> Test.rb
> 
> Class Test.rb  
> …  
> end
> 
> testing.rb

require ‘Test’

> object = Test.new # It tells error.

Note that Test.rb should say ‘class’ not ‘Class’

Also, it doesn’t really matter what filename you use, but there is a  
common convention that the name of the source file is the lowercased,  
underscored version of the class name. So conventionally you would call  
your file ‘test.rb’. For a file containing class MyTestClass you would  
call it my\_test\_class.rb

HTH,

Brian.

---

<div class="post-metadata">

**Author:** ![thangappan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@thangappan](https://www.ruby-forum.com/u/thangappan)\
**Post date:** [May 11, 2009, 11:13am UTC](https://www.ruby-forum.com/t/including-module/167672/3 "2009-05-11T11:13:35Z")

</div>

On Monday 11 May 2009, Thangappan Mohana sundaram wrote:

> |  
> |testing.rb  
> |  
> |object = Test.new # It tells error.

Add:

require ‘Test’

to testing.rb before calling Test.new (assuming that Test.rb and  
testing.rb  
are in the same directory and that you run ruby from that directory).  
Also,  
notice that:

1. you should write class Test, not class Test.rb (note the downcase c  
in  
class and the absence of the .rb from Test). Class names have nothing in  
common with file names
2. file names are (I think) case senstive in ruby, so if you call your  
file  
Test.rb you’ll need to require ‘Test’; if you call it test.rb you’ll  
need to  
require ‘test’. If you’re on windows, which is not a case sensitive OS,  
you  
may be used to a different behaviour (actually, I’m not completely sure  
of how  
this behaves on windows, as I’ve never used ruby on it)
3. modules in ruby are something entirely different (see the  
documentation for  
the Module class either at [RDoc Documentation](http://www.ruby-doc.org/core/) or using ri:  
ri Module.

For more information you can look at the documentation for the require  
method  
of module Kernel, either at [RDoc Documentation](http://www.ruby-doc.org/core/) or using ri:  
ri  
Kernel#require. You may also find useful reading the free online version  
of  
the Pickaxe book ([Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/)) it’s a  
bit  
outdated, but it should be useful all the same.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![thangappan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@thangappan](https://www.ruby-forum.com/u/thangappan)\
**Post date:** [May 11, 2009, 11:11am UTC](https://www.ruby-forum.com/t/including-module/167672/4 "2009-05-11T11:11:13Z")

</div>

On Mon, May 11, 2009 at 9:42 AM, Thangappan Mohana sundaram \<  
removed\_email\_address@domain.invalid\> wrote:

> end
> 
> testing.rb
> 
> object = Test.new # It tells error.

In your testing.rb add a require like so:

require “Test”

at the top of the file.

Ben

---

<div class="post-metadata">

**Author:** ![thangappan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b19c9b/32.png) [@thangappan](https://www.ruby-forum.com/u/thangappan)\
**Post date:** [February 8, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/including-module/167672/5 "2010-02-08T18:19:55Z")

</div>

Sort of similar type problem to what is already posted here.

I’m two months into Ruby and I can write single file code that purely  
functions from the command line and separate ones that function in  
conjunction with SketchUp. I would like to maximize the  
compartmentalization of modules but am getting stuck.

My understanding is that files that are called with require need to be  
in the path given when ruby -e ‘puts $:’ is typed at the command line.  
So, I have a driver file in the pluggins directory in SketchUp in which  
I require ‘a\_file’ but I get a file not found error.

Error: #\<LoadError: No such file to load – abc\>  
C:\Program Files\Google\Google SketchUp 7\Plugins\test.rb:1:in `require’  
C:\Program Files\Google\Google SketchUp 7\Plugins\test.rb:1

Why isn’t the driver program seeing my module file? The module file  
(Abc.rb) is in the C:/Ruby/lib/ruby/site\_ruby directory. The driver  
file (test.rb) calls the module on the first line with require ‘abc’  
which generates the error.

Jessica
