# Looking for Ruby equivalent to Perl's FindBin

**URL:** <https://www.ruby-forum.com/t/looking-for-ruby-equivalent-to-perls-findbin/52647>\
**Category:** Ruby\
**Created:** [January 17, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/looking-for-ruby-equivalent-to-perls-findbin/52647 "2006-01-17T15:36:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cnick](https://www.ruby-forum.com/u/cnick)\
**Post date:** [January 17, 2006, 3:36pm UTC](https://www.ruby-forum.com/t/looking-for-ruby-equivalent-to-perls-findbin/52647/1 "2006-01-17T15:36:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cnick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cnick](https://www.ruby-forum.com/u/cnick)\
**Post date:** [January 17, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/looking-for-ruby-equivalent-to-perls-findbin/52647/2 "2006-01-17T15:42:50Z")

</div>

On 17/01/06, Chris N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
