# 'requiring' a local module

**URL:** <https://www.ruby-forum.com/t/requiring-a-local-module/137607>\
**Category:** Ruby\
**Created:** [May 14, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607 "2008-05-14T16:44:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 14, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607/1 "2008-05-14T16:44:38Z")

</div>

i know this is dirt simple, but i am totally not getting it…

i have a file called “syndication.rb” that includes some modules that i  
need…

in the same directory, i have a file that says:

require ‘syndication/rhapsody’

when i try to run the program, i get:

LoadError: no such file to load â€” syndication/rhapsody

anyone have any ideas?

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 14, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607/2 "2008-05-14T17:36:34Z")

</div>

Sergio R. wrote:

> i have a file called “syndication.rb”  
> in the same directory, i have a file that says:  
> require ‘syndication/rhapsody’

Of course this is wrong. This ‘require’ loads a file  
‘syndication/rhapsody.rb’. But you want to load the file  
‘syndication.rb’.

So change it to:

require ‘syndication’

BTW, if you’re launching your program not from the directory where it  
resides, then loading the module would fail. You’ll have to tell ruby to  
load files also from the directory in which you program resides:

$:.unshift File.dirname( **FILE** )  
require ‘syndication’

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 15, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607/3 "2008-05-15T20:27:52Z")

</div>

just for the record, i found that the above was indeed the case!

thanks so much!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 17, 2008, 10:24am UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607/4 "2008-05-17T10:24:16Z")

</div>

Peter B. wrote:

> irb(main):002:0\>  
> zaphy@servierer:~/temp/ruby-lang$ ls lib/  
> albert\_lib.rb cool\_lib.rb other\_lib.rb  
> zaphy@servierer:~/temp/ruby-lang$ irb  
> irb(main):001:0\> require “lib/cool\_lib”  
> LoadError: no such file to load – other\_lib  
> from ./lib/cool\_lib.rb:1:in `require’  
> from ./lib/cool\_lib.rb:1  
> from (irb):1  
> irb(main):002:0\> require “lib/albert\_lib”  
> =\> true  
> irb(main):003:0\>

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 16, 2008, 10:16am UTC](https://www.ruby-forum.com/t/requiring-a-local-module/137607/5 "2008-05-16T10:16:47Z")

</div>

Albert S. wrote:

> BTW, if you’re launching your program not from the directory where it  
> resides, then loading the module would fail. You’ll have to tell ruby to  
> load files also from the directory in which you program resides:
> 
> $:.unshift File.dirname( **FILE** )  
> require ‘syndication’

irb(main):001:0\> $:[-1]  
=\> “.”  
irb(main):002:0\>
