file location

Discussion in 'Ruby' started by Eko Budi Setiyo, Jan 11, 2005.

  1. 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
     
    Eko Budi Setiyo, Jan 11, 2005
    #1
    1. Advertising

  2. 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.)
     
    Joel VanderWerf, Jan 11, 2005
    #2
    1. Advertising

  3. 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.)
    >
    >
    >
     
    Eko Budi Setiyo, Jan 11, 2005
    #3
  4. Hi,

    In message "Re: file location"
    on Tue, 11 Jan 2005 12:10:19 +0900, Eko Budi Setiyo <> 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.
     
    Yukihiro Matsumoto, Jan 11, 2005
    #4
  5. Yukihiro Matsumoto wrote:

    >Hi,
    >
    >In message "Re: file location"
    > on Tue, 11 Jan 2005 12:10:19 +0900, Eko Budi Setiyo <> 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
     
    Eko Budi Setiyo, Jan 11, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Dalessandro
    Replies:
    0
    Views:
    617
    Luke Dalessandro
    Jan 15, 2006
  2. zxo102
    Replies:
    0
    Views:
    418
    zxo102
    Aug 1, 2006
  3. saiho.yuen
    Replies:
    3
    Views:
    438
    kaeli
    Sep 14, 2004
  4. John Bailo

    IE7 shows location even if location=no

    John Bailo, Jan 19, 2007, in forum: Javascript
    Replies:
    4
    Views:
    183
    OmegaJunior
    Mar 11, 2007
  5. Replies:
    2
    Views:
    146
Loading...

Share This Page