looking for Ruby equivalent to Perl's FindBin

C

Chris Newman

------_=_NextPart_001_01C61B6E.0E9A9BA6
Content-Type: text/plain

I am looking for a Ruby equivalent to Perl's FindBin module.

What I am trying to do is reference other scripts and data
relative to the Ruby script I am calling, not my current working
directory.

For example, in Perl I can say...

use FindBin qw($RealBin);
use lib "$RealBin/../lib";

or open(IN, "$RealBin/../data/somefile.csv")

If the script I am calling is /some/path/over/there/my_perl.pl,
then $RealBin becomes "/some/path/over/there".

I have Googled about but can't find what I am looking for.

A friend also suggested I use $0 and the fileutils module,
but I don't see how that could work.

Can anyone point me in the right direction?

Thanks in advance,

Chris

------_=_NextPart_001_01C61B6E.0E9A9BA6--
 
A

Austin Ziegler

What I am trying to do is reference other scripts and data
relative to the Ruby script I am calling, not my current working
directory.

File.dirname(__FILE__) from the script where data is relative will
give you what you want.

-austin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top