Forum: Ruby rakefile "$0" path in rake

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter P. (Guest)
on 2009-01-13 16:58
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}"
badboy (Guest)
on 2009-01-13 17:03
(Received via mailing list)
Peter Pk schrieb:
> p "running #{myPath}"
try using the "magic variable" __FILE__ ?
James G. (Guest)
on 2009-01-13 17:05
(Received via mailing list)
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 G. II
Peter P. (Guest)
on 2009-01-13 17:37
badboy wrote:
> Peter Pk schrieb:
>> p "running #{myPath}"
> try using the "magic variable" __FILE__ ?

Thanks! Thats it!
This topic is locked and can not be replied to.