__PATH__ like __FILE__?

D

Deniz Dogan

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
 
J

James Edward Gray II

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
 
O

Olivier Renaud

Le vendredi 02 mars 2007 14:55, Deniz Dogan a =E9crit=A0:
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 :

=46ile.expand_path(__FILE__)
=46ile.dirname(File.expand_path(__FILE__))

=2D-=20
Olivier Renaud
 
D

Deniz Dogan

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

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

Louis J Scoras

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

# ...
 
D

Daniel DeLorme

Olivier said:
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
 
T

Trans

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.
 

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,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top