rakefile "$0" path in rake

Discussion in 'Ruby' started by Peter Pk, Jan 13, 2009.

  1. Peter Pk

    Peter Pk Guest

    Is there a way to get the path to "itself" in a rakefile loaded by rake?

    ie for:
    rake --rakefile ../../some/path/to/rakefile.rb

    ***

    inside rakefile

    myPath = # ????
    p "running #{myPath}"
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Pk, Jan 13, 2009
    #1
    1. Advertising

  2. Peter Pk

    badboy Guest

    Peter Pk schrieb:
    > Is there a way to get the path to "itself" in a rakefile loaded by rake?
    >
    > ie for:
    > rake --rakefile ../../some/path/to/rakefile.rb
    >
    > ***
    >
    > inside rakefile
    >
    > myPath = # ????
    > p "running #{myPath}"

    try using the "magic variable" __FILE__ ?
     
    badboy, Jan 13, 2009
    #2
    1. Advertising

  3. Peter Pk

    James Gray Guest

    On Jan 13, 2009, at 8:57 AM, Peter Pk wrote:

    > Is there a way to get the path to "itself" in a rakefile loaded by
    > rake?


    Sure.

    > ***
    >
    > inside rakefile
    >
    > myPath = # ????


    my_path = File.expand_path(__FILE__)

    > p "running #{myPath}"


    Hope that helps.

    James Edward Gray II
     
    James Gray, Jan 13, 2009
    #3
  4. Peter Pk

    Peter Pk Guest

    badboy wrote:
    > Peter Pk schrieb:
    >> p "running #{myPath}"

    > try using the "magic variable" __FILE__ ?


    Thanks! Thats it!
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Pk, Jan 13, 2009
    #4
    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. T. Onoma

    Don't know how to rake Rakefile

    T. Onoma, Aug 23, 2004, in forum: Ruby
    Replies:
    8
    Views:
    168
    James Britt
    Aug 23, 2004
  2. Joe Van Dyk
    Replies:
    2
    Views:
    108
    Damphyr
    Jan 31, 2006
  3. mikshir
    Replies:
    0
    Views:
    128
    mikshir
    Sep 8, 2006
  4. John Gabriele
    Replies:
    1
    Views:
    174
    Suraj Kurapati
    Dec 5, 2006
  5. peppermonkey
    Replies:
    1
    Views:
    251
    Gregory Brown
    Feb 10, 2007
Loading...

Share This Page