Method: File.relative_path
- Defined in:
- lib/yard/core_ext/file.rb
.relative_path(from, to) ⇒ String
Turns a path to
into a relative path from starting point from
. The argument from
is assumed to be a filename. To treat it as a directory, make sure it ends in File::SEPARATOR
(‘/’ on UNIX filesystems).
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yard/core_ext/file.rb', line 19 def self.relative_path(from, to) from = (from).split(SEPARATOR) to = (to).split(SEPARATOR) from.length.times do break if from[0] != to[0] from.shift; to.shift end from.pop join(*(from.map { RELATIVE_PARENTDIR } + to)) end |