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
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2200
def split()
array = File.split(@path)
raise TypeError, 'wrong argument type nil (expected Array)' unless Array === array
array.map {|f| self.class.new(f) }
end
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:%%^^&&>]