Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > file location

Reply
Thread Tools

file location

 
 
Eko Budi Setiyo
Guest
Posts: n/a
 
      01-11-2005
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



 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      01-11-2005
Eko Budi Setiyo wrote:
> 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.)


 
Reply With Quote
 
 
 
 
Eko Budi Setiyo
Guest
Posts: n/a
 
      01-11-2005
Thanks you very much

Joel VanderWerf wrote:

> Eko Budi Setiyo wrote:
>
>> 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.)
>
>
>





 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      01-11-2005
Hi,

In message "Re: file location"
on Tue, 11 Jan 2005 12:10:19 +0900, Eko Budi Setiyo <(E-Mail Removed)> writes:

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


 
Reply With Quote
 
Eko Budi Setiyo
Guest
Posts: n/a
 
      01-11-2005
Yukihiro Matsumoto wrote:

>Hi,
>
>In message "Re: file location"
> on Tue, 11 Jan 2005 12:10:19 +0900, Eko Budi Setiyo <(E-Mail Removed)> writes:
>
>|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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Location, location, location =?Utf-8?B?VHJhY2V5?= Wireless Networking 2 02-17-2007 08:37 PM
NAT location and VPN termination location K.J. 44 Cisco 0 09-12-2006 02:17 PM
after an image is moved to a new location, how to delete the image at the old location? zxo102 Python 0 08-01-2006 04:58 PM
How to trick a page into running at a location different from it'sphysical location? Luke Dalessandro ASP .Net 0 01-15-2006 05:59 AM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM



Advertisments