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
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 385
def initialize(path)
@path = File.path(path).dup
rescue TypeError => e
raise e.class, "Pathname.new requires a String, #to_path or #to_str", cause: nil
end
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:.>