'requiring' a local module...

S

Sergio Ruiz

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!
 
A

Albert Schlef

Sergio said:
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'
 
S

Sergio Ruiz

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

thanks so much!
 
P

Peter Bunyan

Albert said:
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>
 
S

Stefan Mahlitz

Peter said:
Albert said:
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>

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,204
Messages
2,571,062
Members
47,669
Latest member
johnmaxwell

Latest Threads

Top