Question

I think I'm missing something here. I have a directory like this:

myapp
|-lib
  |-package1
    |-dostuff.rb
  |-package2
    |-dostuff.rb

From an irb console I'm trying to test the library before I add it to my real project (a Rails app). However, typing this:

require 'lib/package1/dostuff'

returns an error saying it can't find the file to load. I added the lib directory to the load path but I'm not able to load the file.

What am I forgetting? The two filenames don't have to be the same but that's how they are to begin with (they are auto-generated from some web services I need to call using soap4r; each package represents a different web service API group)

Was it helpful?

Solution

If the directory "lib" is in the load path, the argument to require must be relative to lib. So require 'package1/dostuff' without the lib, otherwise it will look for lib/lib/package1/dostuff.rb.

OTHER TIPS

In Ruby 1.9 there's the new require_relative method, which would let you do require_relative "../package2/dostuff" from within package1/dostuff.rb.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top