file location

E

Eko Budi Setiyo

Hi everybody


#file1.rb
#Location: /home/eko
puts Dir.pwd
require 'directory1/file2.rb


#file2.rb
#Location: /home/eko/directory1
puts Dir.pwd



if I run "ruby file1.rb
will produce:
"/home/eko"
"/home/eko"

What comand that I should you in file2.rb that will "automatically"
produce result
"/home/eko"
"/home/eko/directory1/file2.rb"


regards
Eko
 
J

Joel VanderWerf

Eko said:
Hi everybody


#file1.rb
#Location: /home/eko
puts Dir.pwd require 'directory1/file2.rb


#file2.rb
#Location: /home/eko/directory1
puts Dir.pwd



if I run "ruby file1.rb
will produce:
"/home/eko"
"/home/eko"

What comand that I should you in file2.rb that will "automatically"
produce result
"/home/eko"
"/home/eko/directory1/file2.rb"

#file1.rb
puts Dir.pwd # /tmp
require 'directory1/file2.rb'


#file2.rb
puts Dir.pwd # /tmp

Dir.chdir(File.dirname(__FILE__)) do
puts Dir.pwd # /tmp/directory1
end

puts Dir.pwd # /tmp

(But note that Dir.chdir with a block is not threadsafe.)
 
E

Eko Budi Setiyo

Thanks you very much

Joel said:
#file1.rb
puts Dir.pwd # /tmp
require 'directory1/file2.rb'


#file2.rb
puts Dir.pwd # /tmp

Dir.chdir(File.dirname(__FILE__)) do
puts Dir.pwd # /tmp/directory1
end

puts Dir.pwd # /tmp

(But note that Dir.chdir with a block is not threadsafe.)
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: file location"

|What comand that I should you in file2.rb that will "automatically"
|produce result
|"/home/eko"
|"/home/eko/directory1/file2.rb"

The current directory (which is returned from Dir.pwd) is something
different from the directory where the program are stored. What about
__FILE__ pseudo constant that shows the file name of the loading
program?

matz.
 
E

Eko Budi Setiyo

Yukihiro said:
Hi,

In message "Re: file location"

|What comand that I should you in file2.rb that will "automatically"
|produce result
|"/home/eko"
|"/home/eko/directory1/file2.rb"

The current directory (which is returned from Dir.pwd) is something
different from the directory where the program are stored. What about
__FILE__ pseudo constant that shows the file name of the loading
program?

matz.
I litle bit feel shame to admit it, but your suggestion is the shortest
solution.
Why I can't find this __FILE__ in all the tutorial that i read before I
submit to this mailling list
__FILE__ is the exactly what I want

regards
eko
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top