From: Tom Sawyer Date: 2003-01-14T07:00:34+09:00 Subject: Re: 'require' search path On Monday 13 January 2003 05:30 am, Tobias Peters wrote: > On Sun, 12 Jan 2003, Tom Sawyer wrote: > > On Saturday 11 January 2003 04:23 am, Tim Bates wrote: > > > I wish 'require' would count the current directory as the directory the > > > file is in, rather than the directory the script is being run from. > > > > wish granted: > > [...] > > This does not solve Tim's problem, as I understand it. > > "I wish 'require' would count the current directory as the directory the > file is in, rather than the directory the script is being run from." > sounds like he wants "require" to behave like C's "#include" and html's > "href": relative paths should be relative to the directory of the > file that contains the "require" statement / "#include" directive / "href" > attribute. Your solution would treat the path as relative to the current > directory of the ruby process which is what he does explicitly not want > (Tim calls this "the directory the script is being run from"). umm...unless i'm missing something, and the test i ran somehow worked for unbeknown reasons, i would have to say this exactly what i have done. there may be some flaw in the design that i have overlooked, but this is the simple contruct: when a file is required, the location of that file being required is added to the load path. thus any subsequent requires from within that require and (requires within those requires) will be findable without specifiying the path relative to the running process. > How about this: > > def import(what) > require File.join(File.dirname(caller[0]), what) > end > > and use "import" instead of "require". ah, the use of caller is nice! i'll have to think about its use in my solution. very nice solution. short and sweet. the only problem i see with it is that it can't be used inplace of require, which for me defeats part of the purpose. -- tom sawyer, aka transami transami@transami.net .''. .''. . *''* :_\/_: . :_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'. .''.: /\ : ./)\ ':'* /\ * : '..'. -=:o:=- :_\/_:'.:::. | ' *''* * '.\'/.' _\(/_'.':'.' : /\ : ::::: = *_\/_* -= o =- /)\ ' * '..' ':::' === * /\ * .'/.\'. '._____ * | *..* : |. |' .---"| * | _ .--'| || | _| | * | .-'| __ | | | || | .-----. | |' | || | | | | | || | ___' ' /"\ | '-."". '-' '-.' '` |_. ------------------------------------------------------------