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.
243ae676bf9fcdbcf0118567bc45f8af?d=identicon&s=25 Peter Pk (peterk)
on 2009-01-13 15: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}"
245a6d22816ecaeac1c9080ad183b859?d=identicon&s=25 badboy (Guest)
on 2009-01-13 16:03
(Received via mailing list)
Peter Pk schrieb:
> p "running #{myPath}"
try using the "magic variable" __FILE__ ?
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-01-13 16: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 Gray II
243ae676bf9fcdbcf0118567bc45f8af?d=identicon&s=25 Peter Pk (peterk)
on 2009-01-13 16: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.