Skip to content
class method

File.path

(::string | ::_ToPath path) -> ::String
File.path(path) → string
Example
Returns the string representation of the path

   File.path(File::NULL)           #=> "/dev/null"
   File.path(Pathname.new("/tmp")) #=> "/tmp"

If path is not a String:

  1. If it has the to_path method, that method will be called to coerce to a String.

  2. Otherwise, or if the coerced result is not a String too, the standard coersion using to_str method will take place on that object. (See also String.try_convert)

The coerced string must satisfy the following conditions:

  1. It must be in an ASCII-compatible encoding; otherwise, an Encoding::CompatibilityError is raised.

  2. It must not contain the NUL character (\0); otherwise, an ArgumentError is raised.

See also .owned? .pipe? .open .readable? also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0