Skip to content

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

class method

Pathname.new

(::string | ::Pathname) -> ::Pathname
Pathname.new(path) → new_pathname

Returns a new Pathname object based on the given path, via File.path(path).dup. the path may be a String, a File, a Dir, or another Pathname; see File.path:

Example
Pathname.new('.')               # => #<Pathname:.>
Pathname.new('/usr/bin')        # => #<Pathname:/usr/bin>
Pathname.new(File.new('LEGAL')) # => #<Pathname:LEGAL>
Pathname.new(Dir.new('.'))      # => #<Pathname:.>
Pathname.new(Pathname.new('.')) # => #<Pathname:.>
See also .mktmpdir .pwd .glob #+ also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0