find the path of a directory in ruby

To find the path of a directory in Ruby, you can use the File.expand_path method, passing the directory name as an argument:

main.rb
dir_path = File.expand_path("my_directory")
44 chars
2 lines

This will return the absolute path of the "my_directory" directory. If you need to specify a base directory other than the current working directory, you can provide a second argument to expand_path:

main.rb
base_dir = "/home/user/Documents"
dir_path = File.expand_path("my_directory", base_dir)
88 chars
3 lines

This will return the absolute path of "my_directory" within the "/home/user/Documents" directory.

gistlibby LogSnag