Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#split

() -> [ ::Pathname, ::Pathname ]
split → array_of_pathnames

Returns a 2-element array of pathnames containing the dirname and basename of the path in self:

Example
Pathname('doc/maintainers.md').split # => [#<Pathname:doc>, #<Pathname:maintainers.md>]
Pathname('doc/').split               # => [#<Pathname:.>, #<Pathname:doc>]
Pathname('README.md').split          # => [#<Pathname:.>, #<Pathname:README.md>]
Pathname('/tmp/nosuch').split        # => [#<Pathname:/tmp>, #<Pathname:nosuch>]
Pathname('@@##$$/%%^^&&').split      # => [#<Pathname:@@##$$>, #<Pathname:%%^^&&>]
See also #socket? #split_names #size? #stat also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0