Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#realpath
(?::string | ::Pathname base_dir) -> ::Pathname
realpath → new_pathname
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 2230
def realpath(...) self.class.new(File.realpath(@path, ...)) end
Returns a new pathname containing the real (absolute) pathname of the path in self; the new path is the path in the actual filesystem, and does not contain useless dot-entries ('.' or '..') or symbolic links:
Example
Pathname('/etc/./passwd/../../var').realpath # => #<Pathname:/var>
All components of the new path must exist:
Example
Pathname('/etc/./passwd/../../var/nosuch').realpath # Raises Errno::ENOENT: No such file or directory.
Method realdirpath is similar, but does not require the last component to exist.
See also
#realdirpath
#relative?
#readlink
#relative_path_from
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0