Skip to content

Useful Ruby Scripts

muh182 edited this page Nov 6, 2014 · 2 revisions

Absolute vs. Relative Path

Sometimes, there is a need to use the relative or absolute path to load a file. For example, if you have a file located in the a sub-directory to require the file, you can use the following scripts:

  • Method 1:
require "#{File.dirname(__FILE__)}/resources/filename"

or

  • Method 2:
require "#{Dir.pwd}/resources/filename"

The first method uses the relative path, meaning '.', while the second method uses the absolute path.