![]() You’d have to do this cleanup yourself if you used. What you really need is File.join(): this method concatenates arguments with a single slash, and will ensure that there is only one slash between each argument. OMG I’ve always wanted to know - what’s the best way to make a pathname out of lots of different strings? This is the folder you are currently in - nothing to do with the file that is executing. What’s the working directory and how do I find it? If you only have to worry about supporting Ruby 2.0.0 and above, you can use the _dir_ constant instead. If you aren’t interested in the pathname and want the file’s absolute directory without the filename, combine the previous method with the dirname method. How do I find the absolute directory name of the currently executing file? ![]() Now we know the name of the currently executing file, we can pass it to the expand_path method of the File class.Įxpand_path returns the absolute pathname of the file provided as an argument. How do I get the absolute pathname of the currently executing file? _FILE_ is a constant that represents the name of the file that is currently executing. You’ve probably seen this keyword used in Ruby. relative path - a partial representation of the absolute path because it starts from some other directory.absolute path - the full path of the file in the file system: it starts with the root directory and includes all the directories between it and the file in question.you’ve executed the command ruby foo.rb from the terminal.which lives in the file system at /Users/me/myDir/foo.rb.You’ve got a file, but where does it live? Which directory are you in? Where am I? What’s my name?
0 Comments
Leave a Reply. |