2004-01-30 Fri

[別の年の同じ日: 2006 2007 2008 2009 2010 2011

相対パスを求める はてぶ

pathname を使って次のように.

require 'pathname'

path = Pathname.new("/home/fumi/test.txt")
from = Pathname.new("/home/fumi/test/1")

relative_path = path.relative_path_from(from)


=> #<Pathname:../../test.txt>