require '../foo/bar' 
Author Message
 require '../foo/bar'

Should that work?
--
Tobias Reif
http://www.*-*-*.com/

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.*-*-*.com/



Wed, 21 Apr 2004 05:31:11 GMT  
 require '../foo/bar'

Quote:

> Should that work?

Why not?

BTW, it works ;-)

Regards,

  Michael

--
Michael Neumann
merlin.zwo InfoDesign GmbH
http://www.merlin-zwo.de



Wed, 21 Apr 2004 05:44:53 GMT  
 require '../foo/bar'
Hello --

Quote:

> Should that work?

Yes.  Doesn't it?

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 05:44:10 GMT  
 require '../foo/bar'

Quote:

> Yes.  Doesn't it?

:) :( don't ask... ; I'm inside a big chaos.

Seriously; thanks. If it should, then it will.

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 05:58:36 GMT  
 require '../foo/bar'

Quote:

> Yes.  Doesn't it?

 From file a, I require a file b (located in a directory under the
current one), which requires a file c (b and c are located in the same
directory).
For that second require (b requires c), I get a loadError.
If I run b directly (which requires c); no error.
When I run a, I again get the loadError that says b can't load c.
I can require c from a, c form b, but not c from b from a.

?

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 06:14:19 GMT  
 require '../foo/bar'
Hello --

Quote:


> > Yes.  Doesn't it?

>  From file a, I require a file b (located in a directory under the
> current one), which requires a file c (b and c are located in the same
> directory).
> For that second require (b requires c), I get a loadError.
> If I run b directly (which requires c); no error.
> When I run a, I again get the loadError that says b can't load c.
> I can require c from a, c form b, but not c from b from a.

Here's why:

When b is loaded, the working directory is still the higher one.
So "require 'c'" actually executes in the context of that directory,
where there's (I assume) no c.

If you change the require line in b to:

  require "subdir/c"

it will work, though in the long run you might want to manipulate $:.

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 06:20:21 GMT  
 require '../foo/bar'

Quote:

> > Yes.  Doesn't it?

>  From file a, I require a file b (located in a directory under the
> current one), which requires a file c (b and c are located in the same
> directory).
> For that second require (b requires c), I get a loadError.

I tried it and got the same error as you;
---

./b.rb:3:in `require': No such file to load -- c (LoadError)
        from ../b.rb:3
        from ./a.rb:2:in `require'
        from ./a.rb:2
---
if you write the 2nd require as
require '../c'
despite the fact that your code is in ../
it does work;
why all that?
I guess ruby stays in the same dir.. and never changes;

        Armin

Quote:
> If I run b directly (which requires c); no error.
> When I run a, I again get the loadError that says b can't load c.
> I can require c from a, c form b, but not c from b from a.

> ?

> Tobi

--
Armin.

-----------------------------------------------
Armin Roehrl, http://www.approximity.com
"The best way to predict the future is to invent it."
                                          --Alan Kay



Wed, 21 Apr 2004 06:22:48 GMT  
 require '../foo/bar'
David,

Quote:
> Here's why:

> When b is loaded, the working directory is still the higher one.
> So "require 'c'" actually executes in the context of that directory,
> where there's (I assume) no c.

> If you change the require line in b to:

>   require "subdir/c"

> it will work, though in the long run you might want to manipulate $:.

Thanks a lot!
Now: I don't want to change b; various 'a's may be in different places.
So: How can I achive what I want in a? (how exactly would I modify $: ?)

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 06:28:11 GMT  
 require '../foo/bar'
Hello --

Quote:

> David,

> > Here's why:

> > When b is loaded, the working directory is still the higher one.
> > So "require 'c'" actually executes in the context of that directory,
> > where there's (I assume) no c.

> > If you change the require line in b to:

> >   require "subdir/c"

> > it will work, though in the long run you might want to manipulate $:.

> Thanks a lot!
> Now: I don't want to change b; various 'a's may be in different places.
> So: How can I achive what I want in a? (how exactly would I modify $: ?)

If you put this at the top of a:

   $:.unshift "subdir_name"

that should work.

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Wed, 21 Apr 2004 06:31:10 GMT  
 require '../foo/bar'

Quote:
> From file a, I require a file b (located in a directory under the
> current one), which requires a file c (b and c are located in the same
> directory).
> For that second require (b requires c), I get a loadError.
> If I run b directly (which requires c); no error.
> When I run a, I again get the loadError that says b can't load c.
> I can require c from a, c form b, but not c from b from a.

> ?

I still think the best "trick" for this problem is to alter the load
path as David Alan Black has suggested.  In my RubyGems project I have a
lib directory where I keep all my main source files.  In the same base
directory that lib is in I have a tests directory where I keep all my
unit tests.  At the top of each unit test file, before I require any of
my rubygems files, I have the following code: $LOAD_PATH[0, 0] =
'../lib'.  This does the same thing as $:.unshift '../lib', just with a
different syntax.  Now whenever the unit tests require a file (and when
that file requires something else), they all load fine.  This works
great and allows all my core source files to have normal paths for their
requires (so there is no need to change anything when they are installed
globally.)

Ryan Leavengood



Wed, 21 Apr 2004 06:46:59 GMT  
 require '../foo/bar'

Quote:

> If you put this at the top of a:

>    $:.unshift "subdir_name"

> that should work.

That's what I tried before, and that's where I probably made a typo; now
it works.
(unshift in a, require in b)

And you know what? When I leave off the require line in b, Ruby finds
the required class in c all by itself (b and c are in the same dir).
(when I remove the file c from the dir, I get a loadError)
ruby 1.6.3 (2001-03-19) [i386-cygwin]

So now it works without any $:.unshift, and without any require in b.

Funny world.

Adding the require in b brings the loadError, which can be solved by
unshifting the path in a.

Tobi

--
Tobias Reif
http://www.pinkjuice.com/myDigitalProfile.xhtml

go_to('www.ruby-lang.org').get(ruby).play.create.have_fun
http://www.pinkjuice.com/ruby/



Wed, 21 Apr 2004 07:03:32 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. INCLUDE 'FOO.FOR/list'

2. old 'chestnut' - bar codes on reports

3. 'StdCLib required'

4. require 'tk' causes segfault later

5. 'require' search path

6. 'require' error (ver/path)

7. require 'etc'

8. cannot require 'postgres' from cgi

9. require 'aDir'

10. Can I write 'foo.bar[key] = value' ?

11. Problem with require 'nqxml/treeparser'

12. How can I reexecute 'import foo from bar'?

 

 
Powered by phpBB® Forum Software