[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

__PATH__ like __FILE__?

kristnjov

3/2/2007 1:42:00 PM

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
8 Answers

James Gray

3/2/2007 2:04:00 PM

0

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

> 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

Olivier

3/2/2007 2:06:00 PM

0

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__))

--
Olivier Renaud

kristnjov

3/2/2007 2:09:00 PM

0

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.

Louis J Scoras

3/2/2007 2:12:00 PM

0

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
>
>

Deniz;

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

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

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

# ...


--
Lou.

Daniel DeLorme

3/2/2007 2:17:00 PM

0

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

Trans

3/2/2007 2:27:00 PM

0



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?

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

T.


George

3/2/2007 3:16:00 PM

0

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__)

Oh, the choices!

George.

Chad Perrin

3/2/2007 7:28:00 PM

0

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__)

Ooh, that one's pretty.

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