Forum: Ruby looking for Ruby equivalent to Perl's FindBin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8465c52f55212f5482b2a5d75e2df794?d=identicon&s=25 Chris Newman (Guest)
on 2006-01-17 15:36
(Received via mailing list)
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
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (Guest)
on 2006-01-17 15:42
(Received via mailing list)
On 17/01/06, Chris Newman <Chris.Newman@dalsemi.com> wrote:
> 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
This topic is locked and can not be replied to.