Search code examples
rubyrake

Rake and current directory


How do I get the directory where the rakefile.rb is located?

I want to use this as my root directory to locate everything off.


Solution

  • use __FILE__ to get the file name then you can get the directory from there:

    in test.rb

    puts __FILE__
    

    output:

    /users/foo/test.rb
    

    __FILE__ resolves to the full path of the file it is in.

    Use this to get the dir name:

    File.dirname(__FILE__)