'requiring' a local module

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!

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’

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

thanks so much!

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>

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>