Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#dirname
() -> ::Pathname
dirname → new_pathname
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2105
def dirname() self.class.new(File.dirname(@path)) end
Returns a new pathname whose path is all but the last component of the path in self:
Example
Pathname('/usr/lib/linux').basename # => #<Pathname:linux> Pathname('/usr').basename # => #<Pathname:usr> Pathname('/').basename # => #<Pathname:/> Pathname('lib/').basename # => #<Pathname:lib> Pathname('nosuch').basename # => #<Pathname:nosuch>
Components are delimited by File::SEPARATOR and, if non-nil, File::ALT_SEPARATOR.