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

instance method Pathname#root?

root? -> bool[permalink][rdoc]

self がルートディレクトリであれば真を返します。判断は文字列操作によって行われ、ファイルシステムはアクセスされません。



require 'pathname'

Pathname('/').root?         # => true
Pathname('/im/sure').root?  # => false