__PATH__ like __FILE__?

Hello.
I'm rather new to Ruby, so please bare with me. I just want to know if there is anything similar to __FILE__ but which represents either the path to the directory which __FILE__ lies in, or the __FILE__ including the full path to the file?

--Deniz Dogan

Hello.

Hello.

I'm rather new to Ruby, so please bare with me.

Welcome to Ruby then.

I just want to know if there is anything similar to __FILE__ but which represents either the path to the directory which __FILE__ lies in, or the __FILE__ including the full path to the file?

Just ask Ruby to expand it for you:

   File.expand_path(__FILE__)

Hope that helps.

James Edward Gray II

···

On Mar 2, 2007, at 7:55 AM, Deniz Dogan wrote:

You have to use the File.expand_path to do this :

File.expand_path(__FILE__)
File.dirname(File.expand_path(__FILE__))

···

Le vendredi 02 mars 2007 14:55, Deniz Dogan a écrit :

Hello.
I'm rather new to Ruby, so please bare with me. I just want to know if
there is anything similar to __FILE__ but which represents either the
path to the directory which __FILE__ lies in, or the __FILE__ including
the full path to the file?

--Deniz Dogan

--
Olivier Renaud

Deniz;

Take a look at the 'pathname' library included with ruby:

http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pathname.html

You should be able to get all that information by combining it with __FILE__:

    path = Pathname.new(__FILE__)
    p path.dirname
    p path.expand_path

    # ...

···

On 3/2/07, Deniz Dogan <kristnjov@nospam.com> wrote:

Hello.
I'm rather new to Ruby, so please bare with me. I just want to know if
there is anything similar to __FILE__ but which represents either the
path to the directory which __FILE__ lies in, or the __FILE__ including
the full path to the file?

--Deniz Dogan

--
Lou.

I suggested the same a while back as __DIR__. I too think it would be
a good thing to have.

T.

···

On Mar 2, 8:55 am, Deniz Dogan <kristn...@nospam.com> wrote:

Hello.
I'm rather new to Ruby, so please bare with me. I just want to know if
there is anything similar to __FILE__ but which represents either the
path to the directory which __FILE__ lies in, or the __FILE__ including
the full path to the file?

Olivier Renaud wrote:

···

Le vendredi 02 mars 2007 14:55, Deniz Dogan a écrit :

Hello.
I'm rather new to Ruby, so please bare with me. I just want to know if
there is anything similar to __FILE__ but which represents either the
path to the directory which __FILE__ lies in, or the __FILE__ including
the full path to the file?

--Deniz Dogan

You have to use the File.expand_path to do this :

File.expand_path(__FILE__)
File.dirname(File.expand_path(__FILE__))

Thanks to both of you.

Olivier Renaud wrote:

You have to use the File.expand_path to do this :

File.expand_path(__FILE__)
File.dirname(File.expand_path(__FILE__))

Or:
File.expand_path(__FILE__+'/..')

:wink:

Daniel

Or even:

  File.expand_path('..', __FILE__)

Oh, the choices!

George.

···

On 3/3/07, Daniel DeLorme <dan-ml@dan42.com> wrote:

Olivier Renaud wrote:
> You have to use the File.expand_path to do this :
>
> File.expand_path(__FILE__)
> File.dirname(File.expand_path(__FILE__))

Or:
File.expand_path(__FILE__+'/..')

:wink:

Daniel

Ooh, that one's pretty.

···

On Sat, Mar 03, 2007 at 12:15:31AM +0900, George Ogata wrote:

On 3/3/07, Daniel DeLorme <dan-ml@dan42.com> wrote:
>Olivier Renaud wrote:
>> You have to use the File.expand_path to do this :
>>
>> File.expand_path(__FILE__)
>> File.dirname(File.expand_path(__FILE__))
>
>Or:
>File.expand_path(__FILE__+'/..')
>
>;-)
>
>Daniel

Or even:

File.expand_path('..', __FILE__)

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Amazon.com interview candidate: "When C++ is your
hammer, everything starts to look like your thumb."