Generate Absolute File Path In Ruby
Pass a string to File.expand_path
to generate the path to that file or directory. Relative paths will reference your current working directory, and paths prepended with ~
will use the owner's home directory.
File.expand_path('example.rb')
=> "/Users/avogel/My/Working/Directory/example.rb"
File.expand_path('~/example.rb')
=> "/Users/avogel/example.rb"
Tweet