Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > pathnameライブラリ > Pathnameクラス > parent

instance method Pathname#parent

parent -> Pathname[permalink][rdoc]

self の親ディレクトリを指す新しい Pathname オブジェクトを返します。

例 絶対パス

require "pathname"

path = Pathname("/usr")
path        # => #<Pathname:/usr>
path.parent # => #<Pathname:/>
例 相対パス

require "pathname"

path = Pathname("foo/bar")
path.parent               # => #<Pathname:foo>
path.parent.parent        # => #<Pathname:.>
path.parent.parent.parent # => #<Pathname:..>