Ruby 4.0 リファレンスマニュアル

instance method Pathname#root?

root? -> bool[permalink][rdoc][edit]

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

require 'pathname'

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