[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

'requiring' a local module...

Sergio Ruiz

5/14/2008 2:45:00 PM

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!
--
Posted via http://www.ruby-....

4 Answers

Albert Schlef

5/14/2008 3:37:00 PM

0

Sergio Ruiz 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'

--
Posted via http://www.ruby-....

Sergio Ruiz

5/15/2008 6:28:00 PM

0

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

thanks so much!

--
Posted via http://www.ruby-....

Peter Bunyan

5/16/2008 8:17:00 AM

0

Albert Schlef 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>
--
Posted via http://www.ruby-....

Stefan Mahlitz

5/17/2008 8:24:00 AM

0

Peter Bunyan wrote:
> Albert Schlef 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>

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>