File: C:/Ruby27-x64/share/doc/ruby/html/Pathname.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class Pathname - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "./";
var index_rel_prefix = "./";
</script>
<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>
<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="class">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="./index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="./table_of_contents.html#pages">Pages</a>
<a href="./table_of_contents.html#classes">Classes</a>
<a href="./table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div class="nav-section">
<h3>Table of Contents</h3>
<ul class="link-list" role="directory">
<li><a href="#class-Pathname-label-Examples">Examples</a>
<li><a href="#class-Pathname-label-Example+1-3A+Using+Pathname">Example 1: Using Pathname</a>
<li><a href="#class-Pathname-label-Example+2-3A+Using+standard+Ruby">Example 2: Using standard Ruby</a>
<li><a href="#class-Pathname-label-Example+3-3A+Special+features">Example 3: Special features</a>
<li><a href="#class-Pathname-label-Breakdown+of+functionality">Breakdown of functionality</a>
<li><a href="#class-Pathname-label-Core+methods">Core methods</a>
<li><a href="#class-Pathname-label-File+status+predicate+methods">File status predicate methods</a>
<li><a href="#class-Pathname-label-File+property+and+manipulation+methods">File property and manipulation methods</a>
<li><a href="#class-Pathname-label-Directory+methods">Directory methods</a>
<li><a href="#class-Pathname-label-IO">IO</a>
<li><a href="#class-Pathname-label-Utilities">Utilities</a>
<li><a href="#class-Pathname-label-Method+documentation">Method documentation</a>
</ul>
</div>
<div id="class-metadata">
<div id="parent-class-section" class="nav-section">
<h3>Parent</h3>
<p class="link"><a href="Object.html">Object</a>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-getwd">::getwd</a>
<li ><a href="#method-c-glob">::glob</a>
<li ><a href="#method-c-new">::new</a>
<li ><a href="#method-c-pwd">::pwd</a>
<li ><a href="#method-i-2B">#+</a>
<li ><a href="#method-i-2F">#/</a>
<li ><a href="#method-i-3C-3D-3E">#<=></a>
<li ><a href="#method-i-3D-3D">#==</a>
<li ><a href="#method-i-3D-3D-3D">#===</a>
<li ><a href="#method-i-absolute-3F">#absolute?</a>
<li ><a href="#method-i-ascend">#ascend</a>
<li ><a href="#method-i-atime">#atime</a>
<li ><a href="#method-i-basename">#basename</a>
<li ><a href="#method-i-binread">#binread</a>
<li ><a href="#method-i-binwrite">#binwrite</a>
<li ><a href="#method-i-birthtime">#birthtime</a>
<li ><a href="#method-i-blockdev-3F">#blockdev?</a>
<li ><a href="#method-i-chardev-3F">#chardev?</a>
<li ><a href="#method-i-children">#children</a>
<li ><a href="#method-i-chmod">#chmod</a>
<li ><a href="#method-i-chown">#chown</a>
<li ><a href="#method-i-cleanpath">#cleanpath</a>
<li ><a href="#method-i-ctime">#ctime</a>
<li ><a href="#method-i-delete">#delete</a>
<li ><a href="#method-i-descend">#descend</a>
<li ><a href="#method-i-directory-3F">#directory?</a>
<li ><a href="#method-i-dirname">#dirname</a>
<li ><a href="#method-i-each_child">#each_child</a>
<li ><a href="#method-i-each_entry">#each_entry</a>
<li ><a href="#method-i-each_filename">#each_filename</a>
<li ><a href="#method-i-each_line">#each_line</a>
<li ><a href="#method-i-empty-3F">#empty?</a>
<li ><a href="#method-i-entries">#entries</a>
<li ><a href="#method-i-eql-3F">#eql?</a>
<li ><a href="#method-i-executable-3F">#executable?</a>
<li ><a href="#method-i-executable_real-3F">#executable_real?</a>
<li ><a href="#method-i-exist-3F">#exist?</a>
<li ><a href="#method-i-expand_path">#expand_path</a>
<li ><a href="#method-i-extname">#extname</a>
<li ><a href="#method-i-file-3F">#file?</a>
<li ><a href="#method-i-find">#find</a>
<li ><a href="#method-i-fnmatch">#fnmatch</a>
<li ><a href="#method-i-fnmatch-3F">#fnmatch?</a>
<li ><a href="#method-i-freeze">#freeze</a>
<li ><a href="#method-i-ftype">#ftype</a>
<li ><a href="#method-i-glob">#glob</a>
<li ><a href="#method-i-grpowned-3F">#grpowned?</a>
<li ><a href="#method-i-join">#join</a>
<li ><a href="#method-i-lchmod">#lchmod</a>
<li ><a href="#method-i-lchown">#lchown</a>
<li ><a href="#method-i-lstat">#lstat</a>
<li ><a href="#method-i-make_link">#make_link</a>
<li ><a href="#method-i-make_symlink">#make_symlink</a>
<li ><a href="#method-i-mkdir">#mkdir</a>
<li ><a href="#method-i-mkpath">#mkpath</a>
<li ><a href="#method-i-mountpoint-3F">#mountpoint?</a>
<li ><a href="#method-i-mtime">#mtime</a>
<li ><a href="#method-i-open">#open</a>
<li ><a href="#method-i-opendir">#opendir</a>
<li ><a href="#method-i-owned-3F">#owned?</a>
<li ><a href="#method-i-parent">#parent</a>
<li ><a href="#method-i-pipe-3F">#pipe?</a>
<li ><a href="#method-i-read">#read</a>
<li ><a href="#method-i-readable-3F">#readable?</a>
<li ><a href="#method-i-readable_real-3F">#readable_real?</a>
<li ><a href="#method-i-readlines">#readlines</a>
<li ><a href="#method-i-readlink">#readlink</a>
<li ><a href="#method-i-realdirpath">#realdirpath</a>
<li ><a href="#method-i-realpath">#realpath</a>
<li ><a href="#method-i-relative-3F">#relative?</a>
<li ><a href="#method-i-relative_path_from">#relative_path_from</a>
<li ><a href="#method-i-rename">#rename</a>
<li ><a href="#method-i-rmdir">#rmdir</a>
<li ><a href="#method-i-rmtree">#rmtree</a>
<li ><a href="#method-i-root-3F">#root?</a>
<li ><a href="#method-i-setgid-3F">#setgid?</a>
<li ><a href="#method-i-setuid-3F">#setuid?</a>
<li ><a href="#method-i-size">#size</a>
<li ><a href="#method-i-size-3F">#size?</a>
<li ><a href="#method-i-socket-3F">#socket?</a>
<li ><a href="#method-i-split">#split</a>
<li ><a href="#method-i-stat">#stat</a>
<li ><a href="#method-i-sticky-3F">#sticky?</a>
<li ><a href="#method-i-sub">#sub</a>
<li ><a href="#method-i-sub_ext">#sub_ext</a>
<li ><a href="#method-i-symlink-3F">#symlink?</a>
<li ><a href="#method-i-sysopen">#sysopen</a>
<li ><a href="#method-i-taint">#taint</a>
<li ><a href="#method-i-to_path">#to_path</a>
<li ><a href="#method-i-to_s">#to_s</a>
<li ><a href="#method-i-truncate">#truncate</a>
<li ><a href="#method-i-unlink">#unlink</a>
<li ><a href="#method-i-untaint">#untaint</a>
<li ><a href="#method-i-utime">#utime</a>
<li ><a href="#method-i-world_readable-3F">#world_readable?</a>
<li ><a href="#method-i-world_writable-3F">#world_writable?</a>
<li ><a href="#method-i-writable-3F">#writable?</a>
<li ><a href="#method-i-writable_real-3F">#writable_real?</a>
<li ><a href="#method-i-write">#write</a>
<li ><a href="#method-i-zero-3F">#zero?</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-Pathname">
<h1 id="class-Pathname" class="class">
class Pathname
</h1>
<section class="description">
<p><a href="Pathname.html"><code>Pathname</code></a> represents the name of a file or directory on the filesystem, but not the file itself.</p>
<p>The pathname depends on the Operating System: Unix, Windows, etc. This library works with pathnames of local OS, however non-Unix pathnames are supported experimentally.</p>
<p>A <a href="Pathname.html"><code>Pathname</code></a> can be relative or absolute. It's not until you try to reference the file that it even matters whether the file exists or not.</p>
<p><a href="Pathname.html"><code>Pathname</code></a> is immutable. It has no method for destructive update.</p>
<p>The goal of this class is to manipulate file path information in a neater way than standard Ruby provides. The examples below demonstrate the difference.</p>
<p><strong>All</strong> functionality from <a href="File.html"><code>File</code></a>, <a href="FileTest.html"><code>FileTest</code></a>, and some from <a href="Dir.html"><code>Dir</code></a> and <a href="FileUtils.html"><code>FileUtils</code></a> is included, in an unsurprising way. It is essentially a facade for all of these, and more.</p>
<h2 id="class-Pathname-label-Examples">Examples<span><a href="#class-Pathname-label-Examples">¶</a> <a href="#top">↑</a></span></h2>
<h3 id="class-Pathname-label-Example+1-3A+Using+Pathname">Example 1: Using <a href="Pathname.html"><code>Pathname</code></a><span><a href="#class-Pathname-label-Example+1-3A+Using+Pathname">¶</a> <a href="#top">↑</a></span></h3>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'pathname'</span>
<span class="ruby-identifier">pn</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"/usr/bin/ruby"</span>)
<span class="ruby-identifier">size</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># 27662</span>
<span class="ruby-identifier">isdir</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">directory?</span> <span class="ruby-comment"># false</span>
<span class="ruby-identifier">dir</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">dirname</span> <span class="ruby-comment"># Pathname:/usr/bin</span>
<span class="ruby-identifier">base</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">basename</span> <span class="ruby-comment"># Pathname:ruby</span>
<span class="ruby-identifier">dir</span>, <span class="ruby-identifier">base</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">split</span> <span class="ruby-comment"># [Pathname:/usr/bin, Pathname:ruby]</span>
<span class="ruby-identifier">data</span> = <span class="ruby-identifier">pn</span>.<span class="ruby-identifier">read</span>
<span class="ruby-identifier">pn</span>.<span class="ruby-identifier">open</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span> }
<span class="ruby-identifier">pn</span>.<span class="ruby-identifier">each_line</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span> }
</pre>
<h3 id="class-Pathname-label-Example+2-3A+Using+standard+Ruby">Example 2: Using standard Ruby<span><a href="#class-Pathname-label-Example+2-3A+Using+standard+Ruby">¶</a> <a href="#top">↑</a></span></h3>
<pre class="ruby"><span class="ruby-identifier">pn</span> = <span class="ruby-string">"/usr/bin/ruby"</span>
<span class="ruby-identifier">size</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">size</span>(<span class="ruby-identifier">pn</span>) <span class="ruby-comment"># 27662</span>
<span class="ruby-identifier">isdir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">pn</span>) <span class="ruby-comment"># false</span>
<span class="ruby-identifier">dir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">pn</span>) <span class="ruby-comment"># "/usr/bin"</span>
<span class="ruby-identifier">base</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">pn</span>) <span class="ruby-comment"># "ruby"</span>
<span class="ruby-identifier">dir</span>, <span class="ruby-identifier">base</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">split</span>(<span class="ruby-identifier">pn</span>) <span class="ruby-comment"># ["/usr/bin", "ruby"]</span>
<span class="ruby-identifier">data</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">pn</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">pn</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span> }
<span class="ruby-constant">File</span>.<span class="ruby-identifier">foreach</span>(<span class="ruby-identifier">pn</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">_</span> }
</pre>
<h3 id="class-Pathname-label-Example+3-3A+Special+features">Example 3: Special features<span><a href="#class-Pathname-label-Example+3-3A+Special+features">¶</a> <a href="#top">↑</a></span></h3>
<pre class="ruby"><span class="ruby-identifier">p1</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"/usr/lib"</span>) <span class="ruby-comment"># Pathname:/usr/lib</span>
<span class="ruby-identifier">p2</span> = <span class="ruby-identifier">p1</span> <span class="ruby-operator">+</span> <span class="ruby-string">"ruby/1.8"</span> <span class="ruby-comment"># Pathname:/usr/lib/ruby/1.8</span>
<span class="ruby-identifier">p3</span> = <span class="ruby-identifier">p1</span>.<span class="ruby-identifier">parent</span> <span class="ruby-comment"># Pathname:/usr</span>
<span class="ruby-identifier">p4</span> = <span class="ruby-identifier">p2</span>.<span class="ruby-identifier">relative_path_from</span>(<span class="ruby-identifier">p3</span>) <span class="ruby-comment"># Pathname:lib/ruby/1.8</span>
<span class="ruby-identifier">pwd</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">pwd</span> <span class="ruby-comment"># Pathname:/home/gavin</span>
<span class="ruby-identifier">pwd</span>.<span class="ruby-identifier">absolute?</span> <span class="ruby-comment"># true</span>
<span class="ruby-identifier">p5</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">"."</span> <span class="ruby-comment"># Pathname:.</span>
<span class="ruby-identifier">p5</span> = <span class="ruby-identifier">p5</span> <span class="ruby-operator">+</span> <span class="ruby-string">"music/../articles"</span> <span class="ruby-comment"># Pathname:music/../articles</span>
<span class="ruby-identifier">p5</span>.<span class="ruby-identifier">cleanpath</span> <span class="ruby-comment"># Pathname:articles</span>
<span class="ruby-identifier">p5</span>.<span class="ruby-identifier">realpath</span> <span class="ruby-comment"># Pathname:/home/gavin/articles</span>
<span class="ruby-identifier">p5</span>.<span class="ruby-identifier">children</span> <span class="ruby-comment"># [Pathname:/home/gavin/articles/linux, ...]</span>
</pre>
<h2 id="class-Pathname-label-Breakdown+of+functionality">Breakdown of functionality<span><a href="#class-Pathname-label-Breakdown+of+functionality">¶</a> <a href="#top">↑</a></span></h2>
<h3 id="class-Pathname-label-Core+methods">Core methods<span><a href="#class-Pathname-label-Core+methods">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are effectively manipulating a <a href="String.html"><code>String</code></a>, because that's all a path is. None of these access the file system except for <a href="Pathname.html#method-i-mountpoint-3F"><code>mountpoint?</code></a>, <a href="Pathname.html#method-i-children"><code>children</code></a>, <a href="Pathname.html#method-i-each_child"><code>each_child</code></a>, <a href="Pathname.html#method-i-realdirpath"><code>realdirpath</code></a> and <a href="Pathname.html#method-i-realpath"><code>realpath</code></a>.</p>
<ul><li>
<p>+</p>
</li><li>
<p><a href="Pathname.html#method-i-join"><code>join</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-parent"><code>parent</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-root-3F"><code>root?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-absolute-3F"><code>absolute?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-relative-3F"><code>relative?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-relative_path_from"><code>relative_path_from</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-each_filename"><code>each_filename</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-cleanpath"><code>cleanpath</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-realpath"><code>realpath</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-realdirpath"><code>realdirpath</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-children"><code>children</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-each_child"><code>each_child</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-mountpoint-3F"><code>mountpoint?</code></a></p>
</li></ul>
<h3 id="class-Pathname-label-File+status+predicate+methods"><a href="File.html"><code>File</code></a> status predicate methods<span><a href="#class-Pathname-label-File+status+predicate+methods">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are a facade for FileTest:</p>
<ul><li>
<p><a href="Pathname.html#method-i-blockdev-3F"><code>blockdev?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-chardev-3F"><code>chardev?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-directory-3F"><code>directory?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-executable-3F"><code>executable?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-executable_real-3F"><code>executable_real?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-exist-3F"><code>exist?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-file-3F"><code>file?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-grpowned-3F"><code>grpowned?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-owned-3F"><code>owned?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-pipe-3F"><code>pipe?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-readable-3F"><code>readable?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-world_readable-3F"><code>world_readable?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-readable_real-3F"><code>readable_real?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-setgid-3F"><code>setgid?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-setuid-3F"><code>setuid?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-size"><code>size</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-size-3F"><code>size?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-socket-3F"><code>socket?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-sticky-3F"><code>sticky?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-symlink-3F"><code>symlink?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-writable-3F"><code>writable?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-world_writable-3F"><code>world_writable?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-writable_real-3F"><code>writable_real?</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-zero-3F"><code>zero?</code></a></p>
</li></ul>
<h3 id="class-Pathname-label-File+property+and+manipulation+methods"><a href="File.html"><code>File</code></a> property and manipulation methods<span><a href="#class-Pathname-label-File+property+and+manipulation+methods">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are a facade for File:</p>
<ul><li>
<p><a href="Pathname.html#method-i-atime"><code>atime</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-birthtime"><code>birthtime</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-ctime"><code>ctime</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-mtime"><code>mtime</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-chmod"><code>chmod(mode)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-lchmod"><code>lchmod(mode)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-chown"><code>chown</code></a>(owner, group)</p>
</li><li>
<p><a href="Pathname.html#method-i-lchown"><code>lchown</code></a>(owner, group)</p>
</li><li>
<p><a href="Pathname.html#method-i-fnmatch"><code>fnmatch</code></a>(pattern, *args)</p>
</li><li>
<p><a href="Pathname.html#method-i-fnmatch-3F"><code>fnmatch?</code></a>(pattern, *args)</p>
</li><li>
<p><a href="Pathname.html#method-i-ftype"><code>ftype</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-make_link"><code>make_link(old)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-open"><code>open</code></a>(*args, &block)</p>
</li><li>
<p><a href="Pathname.html#method-i-readlink"><code>readlink</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-rename"><code>rename(to)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-stat"><code>stat</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-lstat"><code>lstat</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-make_symlink"><code>make_symlink(old)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-truncate"><code>truncate(length)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-utime"><code>utime</code></a>(atime, mtime)</p>
</li><li>
<p><a href="Pathname.html#method-i-basename"><code>basename(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-dirname"><code>dirname</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-extname"><code>extname</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-expand_path"><code>expand_path(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-split"><code>split</code></a></p>
</li></ul>
<h3 id="class-Pathname-label-Directory+methods">Directory methods<span><a href="#class-Pathname-label-Directory+methods">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are a facade for Dir:</p>
<ul><li>
<p><a href="Pathname.html#method-c-glob"><code>Pathname.glob(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-c-getwd"><code>Pathname.getwd</code></a> / <a href="Pathname.html#method-c-pwd"><code>Pathname.pwd</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-rmdir"><code>rmdir</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-entries"><code>entries</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-each_entry"><code>each_entry</code></a>(&block)</p>
</li><li>
<p><a href="Pathname.html#method-i-mkdir"><code>mkdir(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-opendir"><code>opendir(*args)</code></a></p>
</li></ul>
<h3 id="class-Pathname-label-IO"><a href="IO.html"><code>IO</code></a><span><a href="#class-Pathname-label-IO">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are a facade for IO:</p>
<ul><li>
<p><a href="Pathname.html#method-i-each_line"><code>each_line</code></a>(*args, &block)</p>
</li><li>
<p><a href="Pathname.html#method-i-read"><code>read(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-binread"><code>binread(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-readlines"><code>readlines(*args)</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-sysopen"><code>sysopen(*args)</code></a></p>
</li></ul>
<h3 id="class-Pathname-label-Utilities">Utilities<span><a href="#class-Pathname-label-Utilities">¶</a> <a href="#top">↑</a></span></h3>
<p>These methods are a mixture of <a href="Find.html"><code>Find</code></a>, <a href="FileUtils.html"><code>FileUtils</code></a>, and others:</p>
<ul><li>
<p><a href="Pathname.html#method-i-find"><code>find</code></a>(&block)</p>
</li><li>
<p><a href="Pathname.html#method-i-mkpath"><code>mkpath</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-rmtree"><code>rmtree</code></a></p>
</li><li>
<p><a href="Pathname.html#method-i-unlink"><code>unlink</code></a> / <a href="Pathname.html#method-i-delete"><code>delete</code></a></p>
</li></ul>
<h2 id="class-Pathname-label-Method+documentation"><a href="Method.html"><code>Method</code></a> documentation<span><a href="#class-Pathname-label-Method+documentation">¶</a> <a href="#top">↑</a></span></h2>
<p>As the above section shows, most of the methods in <a href="Pathname.html"><code>Pathname</code></a> are facades. The documentation for these methods generally just says, for instance, “See <a href="FileTest.html#method-i-writable-3F"><code>FileTest.writable?</code></a>”, as you should be familiar with the original method anyway, and its documentation (e.g. through <code>ri</code>) will contain more information. In some cases, a brief description will follow.</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-getwd" class="method-detail ">
<div class="method-heading">
<span class="method-name">getwd</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the current working directory as a <a href="Pathname.html"><code>Pathname</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">getwd</span>
<span class="ruby-comment">#=> #<Pathname:/home/zzak/projects/ruby></span>
</pre>
<p>See <a href="Dir.html#method-c-getwd"><code>Dir.getwd</code></a>.</p>
<div class="method-source-code" id="getwd-source">
<pre>static VALUE
path_s_getwd(VALUE klass)
{
VALUE str;
str = rb_funcall(rb_cDir, id_getwd, 0);
return rb_class_new_instance(1, &str, klass);
}</pre>
</div>
</div>
</div>
<div id="method-c-glob" class="method-detail ">
<div class="method-heading">
<span class="method-name">glob</span><span
class="method-args">(p1, p2 = v2, p3 = v3)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns or yields <a href="Pathname.html"><code>Pathname</code></a> objects.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">glob</span>(<span class="ruby-string">"lib/i*.rb"</span>)
<span class="ruby-comment">#=> [#<Pathname:lib/ipaddr.rb>, #<Pathname:lib/irb.rb>]</span>
</pre>
<p>See <a href="Dir.html#method-c-glob"><code>Dir.glob</code></a>.</p>
<div class="method-source-code" id="glob-source">
<pre>static VALUE
path_s_glob(int argc, VALUE *argv, VALUE klass)
{
VALUE args[3];
int n;
n = rb_scan_args(argc, argv, "12", &args[0], &args[1], &args[2]);
if (rb_block_given_p()) {
return rb_block_call_kw(rb_cDir, id_glob, n, args, s_glob_i, klass, RB_PASS_CALLED_KEYWORDS);
}
else {
VALUE ary;
long i;
ary = rb_funcallv_kw(rb_cDir, id_glob, n, args, RB_PASS_CALLED_KEYWORDS);
ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
for (i = 0; i < RARRAY_LEN(ary); i++) {
VALUE elt = RARRAY_AREF(ary, i);
elt = rb_class_new_instance(1, &elt, klass);
rb_ary_store(ary, i, elt);
}
return ary;
}
}</pre>
</div>
</div>
</div>
<div id="method-c-new" class="method-detail ">
<div class="method-heading">
<span class="method-name">new</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Create a <a href="Pathname.html"><code>Pathname</code></a> object from the given <a href="String.html"><code>String</code></a> (or String-like object). If <code>path</code> contains a NULL character (<code>\0</code>), an <a href="ArgumentError.html"><code>ArgumentError</code></a> is raised.</p>
<div class="method-source-code" id="new-source">
<pre>static VALUE
path_initialize(VALUE self, VALUE arg)
{
VALUE str;
if (RB_TYPE_P(arg, T_STRING)) {
str = arg;
}
else {
str = rb_check_funcall(arg, id_to_path, 0, NULL);
if (str == Qundef)
str = arg;
StringValue(str);
}
if (memchr(RSTRING_PTR(str), '\0', RSTRING_LEN(str)))
rb_raise(rb_eArgError, "pathname contains null byte");
str = rb_obj_dup(str);
set_strpath(self, str);
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-pwd" class="method-detail ">
<div class="method-heading">
<span class="method-name">pwd</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the current working directory as a <a href="Pathname.html"><code>Pathname</code></a>.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">getwd</span>
<span class="ruby-comment">#=> #<Pathname:/home/zzak/projects/ruby></span>
</pre>
<p>See <a href="Dir.html#method-c-getwd"><code>Dir.getwd</code></a>.</p>
<div class="method-source-code" id="pwd-source">
<pre>static VALUE
path_s_getwd(VALUE klass)
{
VALUE str;
str = rb_funcall(rb_cDir, id_getwd, 0);
return rb_class_new_instance(1, &str, klass);
}</pre>
</div>
</div>
</div>
</section>
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Instance Methods</h3>
</header>
<div id="method-i-2B" class="method-detail ">
<div class="method-heading">
<span class="method-name">+</span><span
class="method-args">(other)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Appends a pathname fragment to <code>self</code> to produce a new <a href="Pathname.html"><code>Pathname</code></a> object.</p>
<pre class="ruby"><span class="ruby-identifier">p1</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"/usr"</span>) <span class="ruby-comment"># Pathname:/usr</span>
<span class="ruby-identifier">p2</span> = <span class="ruby-identifier">p1</span> <span class="ruby-operator">+</span> <span class="ruby-string">"bin/ruby"</span> <span class="ruby-comment"># Pathname:/usr/bin/ruby</span>
<span class="ruby-identifier">p3</span> = <span class="ruby-identifier">p1</span> <span class="ruby-operator">+</span> <span class="ruby-string">"/etc/passwd"</span> <span class="ruby-comment"># Pathname:/etc/passwd</span>
<span class="ruby-comment"># / is aliased to +.</span>
<span class="ruby-identifier">p4</span> = <span class="ruby-identifier">p1</span> <span class="ruby-operator">/</span> <span class="ruby-string">"bin/ruby"</span> <span class="ruby-comment"># Pathname:/usr/bin/ruby</span>
<span class="ruby-identifier">p5</span> = <span class="ruby-identifier">p1</span> <span class="ruby-operator">/</span> <span class="ruby-string">"/etc/passwd"</span> <span class="ruby-comment"># Pathname:/etc/passwd</span>
</pre>
<p>This method doesn't access the file system; it is pure string manipulation.</p>
<div class="method-source-code" id="2B-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 349</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+</span>(<span class="ruby-identifier">other</span>)
<span class="ruby-identifier">other</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">other</span>) <span class="ruby-keyword">unless</span> <span class="ruby-constant">Pathname</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">other</span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">plus</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_s</span>))
<span class="ruby-keyword">end</span></pre>
</div>
</div>
<div class="aliases">
Also aliased as: <a href="Pathname.html#method-i-2F">/</a>
</div>
</div>
<div id="method-i-2F" class="method-detail method-alias">
<div class="method-heading">
<span class="method-name">/</span><span
class="method-args">(other)</span>
</div>
<div class="method-description">
</div>
<div class="aliases">
Alias for: <a href="Pathname.html#method-i-2B">+</a>
</div>
</div>
<div id="method-i-3C-3D-3E" class="method-detail ">
<div class="method-heading">
<span class="method-name"><=></span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Provides a case-sensitive comparison operator for pathnames.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr'</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin'</span>)
<span class="ruby-comment">#=> -1</span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin'</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin'</span>)
<span class="ruby-comment">#=> 0</span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin'</span>) <span class="ruby-operator"><=></span> <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/USR/BIN'</span>)
<span class="ruby-comment">#=> 1</span>
</pre>
<p>It will return <code>-1</code>, <code>0</code> or <code>1</code> depending on the value of the left argument relative to the right argument. Or it will return <code>nil</code> if the arguments are not comparable.</p>
<div class="method-source-code" id="3C-3D-3E-source">
<pre>static VALUE
path_cmp(VALUE self, VALUE other)
{
VALUE s1, s2;
char *p1, *p2;
char *e1, *e2;
if (!rb_obj_is_kind_of(other, rb_cPathname))
return Qnil;
s1 = get_strpath(self);
s2 = get_strpath(other);
p1 = RSTRING_PTR(s1);
p2 = RSTRING_PTR(s2);
e1 = p1 + RSTRING_LEN(s1);
e2 = p2 + RSTRING_LEN(s2);
while (p1 < e1 && p2 < e2) {
int c1, c2;
c1 = (unsigned char)*p1++;
c2 = (unsigned char)*p2++;
if (c1 == '/') c1 = '\0';
if (c2 == '/') c2 = '\0';
if (c1 != c2) {
if (c1 < c2)
return INT2FIX(-1);
else
return INT2FIX(1);
}
}
if (p1 < e1)
return INT2FIX(1);
if (p2 < e2)
return INT2FIX(-1);
return INT2FIX(0);
}</pre>
</div>
</div>
</div>
<div id="method-i-3D-3D" class="method-detail ">
<div class="method-heading">
<span class="method-name">==</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Compare this pathname with <code>other</code>. The comparison is string-based. Be aware that two different paths (<code>foo.txt</code> and <code>./foo.txt</code>) can refer to the same file.</p>
<div class="method-source-code" id="3D-3D-source">
<pre>static VALUE
path_eq(VALUE self, VALUE other)
{
if (!rb_obj_is_kind_of(other, rb_cPathname))
return Qfalse;
return rb_str_equal(get_strpath(self), get_strpath(other));
}</pre>
</div>
</div>
</div>
<div id="method-i-3D-3D-3D" class="method-detail ">
<div class="method-heading">
<span class="method-name">===</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Compare this pathname with <code>other</code>. The comparison is string-based. Be aware that two different paths (<code>foo.txt</code> and <code>./foo.txt</code>) can refer to the same file.</p>
<div class="method-source-code" id="3D-3D-3D-source">
<pre>static VALUE
path_eq(VALUE self, VALUE other)
{
if (!rb_obj_is_kind_of(other, rb_cPathname))
return Qfalse;
return rb_str_equal(get_strpath(self), get_strpath(other));
}</pre>
</div>
</div>
</div>
<div id="method-i-absolute-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">absolute?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Predicate method for testing whether a path is absolute.</p>
<p>It returns <code>true</code> if the pathname begins with a slash.</p>
<pre class="ruby"><span class="ruby-identifier">p</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/im/sure'</span>)
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">absolute?</span>
<span class="ruby-comment">#=> true</span>
<span class="ruby-identifier">p</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'not/so/sure'</span>)
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">absolute?</span>
<span class="ruby-comment">#=> false</span>
</pre>
<div class="method-source-code" id="absolute-3F-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 224</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">absolute?</span>
<span class="ruby-operator">!</span><span class="ruby-identifier">relative?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-ascend" class="method-detail ">
<div class="method-heading">
<span class="method-name">ascend</span><span
class="method-args">() { |self| ... }</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over and yields a new <a href="Pathname.html"><code>Pathname</code></a> object for each element in the given path in ascending order.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/path/to/some/file.rb'</span>).<span class="ruby-identifier">ascend</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">v</span>}
<span class="ruby-comment">#<Pathname:/path/to/some/file.rb></span>
<span class="ruby-comment">#<Pathname:/path/to/some></span>
<span class="ruby-comment">#<Pathname:/path/to></span>
<span class="ruby-comment">#<Pathname:/path></span>
<span class="ruby-comment">#<Pathname:/></span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'path/to/some/file.rb'</span>).<span class="ruby-identifier">ascend</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">v</span>}
<span class="ruby-comment">#<Pathname:path/to/some/file.rb></span>
<span class="ruby-comment">#<Pathname:path/to/some></span>
<span class="ruby-comment">#<Pathname:path/to></span>
<span class="ruby-comment">#<Pathname:path></span>
</pre>
<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block was given.</p>
<pre>enum = Pathname.new("/usr/bin/ruby").ascend
# ... do stuff ...
enum.each { |e| ... }
# yields Pathnames /usr/bin/ruby, /usr/bin, /usr, and /.</pre>
<p>It doesn't access the filesystem.</p>
<div class="method-source-code" id="ascend-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 325</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ascend</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
<span class="ruby-identifier">path</span> = <span class="ruby-ivar">@path</span>
<span class="ruby-keyword">yield</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">chop_basename</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">path</span>, = <span class="ruby-identifier">r</span>
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">yield</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">del_trailing_separator</span>(<span class="ruby-identifier">path</span>))
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-atime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
atime → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the last access time for the file.</p>
<p>See <a href="File.html#method-c-atime"><code>File.atime</code></a>.</p>
<div class="method-source-code" id="atime-source">
<pre>static VALUE
path_atime(VALUE self)
{
return rb_funcall(rb_cFile, id_atime, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-basename" class="method-detail ">
<div class="method-heading">
<span class="method-name">basename</span><span
class="method-args">(p1 = v1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the last component of the path.</p>
<p>See <a href="File.html#method-c-basename"><code>File.basename</code></a>.</p>
<div class="method-source-code" id="basename-source">
<pre>static VALUE
path_basename(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
VALUE fext;
if (rb_scan_args(argc, argv, "01", &fext) == 0)
str = rb_funcall(rb_cFile, id_basename, 1, str);
else
str = rb_funcall(rb_cFile, id_basename, 2, str, fext);
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-binread" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
binread([length [, offset]]) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns all the bytes from the file, or the first <code>N</code> if specified.</p>
<p>See <a href="IO.html#method-c-binread"><code>File.binread</code></a>.</p>
<div class="method-source-code" id="binread-source">
<pre>static VALUE
path_binread(int argc, VALUE *argv, VALUE self)
{
VALUE args[3];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
return rb_funcallv(rb_cFile, id_binread, 1+n, args);
}</pre>
</div>
</div>
</div>
<div id="method-i-binwrite" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
binwrite(string, [offset] ) → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
binwrite(string, [offset], open_args ) → fixnum
</span>
</div>
<div class="method-description">
<p>Writes <code>contents</code> to the file, opening it in binary mode.</p>
<p>See <a href="IO.html#method-c-binwrite"><code>File.binwrite</code></a>.</p>
<div class="method-source-code" id="binwrite-source">
<pre>static VALUE
path_binwrite(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
return rb_funcallv_kw(rb_cFile, id_binwrite, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}</pre>
</div>
</div>
</div>
<div id="method-i-birthtime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
birthtime → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the birth time for the file. If the platform doesn't have birthtime, raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a>.</p>
<p>See <a href="File.html#method-c-birthtime"><code>File.birthtime</code></a>.</p>
<div class="method-source-code" id="birthtime-source">
<pre>static VALUE
path_birthtime(VALUE self)
{
return rb_funcall(rb_cFile, id_birthtime, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-blockdev-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">blockdev?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-blockdev-3F"><code>FileTest.blockdev?</code></a>.</p>
<div class="method-source-code" id="blockdev-3F-source">
<pre>static VALUE
path_blockdev_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_blockdev_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-chardev-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">chardev?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-chardev-3F"><code>FileTest.chardev?</code></a>.</p>
<div class="method-source-code" id="chardev-3F-source">
<pre>static VALUE
path_chardev_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_chardev_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-children" class="method-detail ">
<div class="method-heading">
<span class="method-name">children</span><span
class="method-args">(with_directory=true)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the children of the directory (files and subdirectories, not recursive) as an array of <a href="Pathname.html"><code>Pathname</code></a> objects.</p>
<p>By default, the returned pathnames will have enough information to access the files. If you set <code>with_directory</code> to <code>false</code>, then the returned pathnames will contain the filename only.</p>
<p>For example:</p>
<pre>pn = Pathname("/usr/lib/ruby/1.8")
pn.children
# -> [ Pathname:/usr/lib/ruby/1.8/English.rb,
Pathname:/usr/lib/ruby/1.8/Env.rb,
Pathname:/usr/lib/ruby/1.8/abbrev.rb, ... ]
pn.children(false)
# -> [ Pathname:English.rb, Pathname:Env.rb, Pathname:abbrev.rb, ... ]</pre>
<p>Note that the results never contain the entries <code>.</code> and <code>..</code> in the directory because they are not children.</p>
<div class="method-source-code" id="children-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 440</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">children</span>(<span class="ruby-identifier">with_directory</span>=<span class="ruby-keyword">true</span>)
<span class="ruby-identifier">with_directory</span> = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@path</span> <span class="ruby-operator">==</span> <span class="ruby-string">'.'</span>
<span class="ruby-identifier">result</span> = []
<span class="ruby-constant">Dir</span>.<span class="ruby-identifier">foreach</span>(<span class="ruby-ivar">@path</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
<span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-string">'.'</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-string">'..'</span>
<span class="ruby-keyword">if</span> <span class="ruby-identifier">with_directory</span>
<span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-identifier">e</span>))
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">e</span>)
<span class="ruby-keyword">end</span>
}
<span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-chmod" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
chmod → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Changes file permissions.</p>
<p>See <a href="File.html#method-c-chmod"><code>File.chmod</code></a>.</p>
<div class="method-source-code" id="chmod-source">
<pre>static VALUE
path_chmod(VALUE self, VALUE mode)
{
return rb_funcall(rb_cFile, id_chmod, 2, mode, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-chown" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
chown → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Change owner and group of the file.</p>
<p>See <a href="File.html#method-c-chown"><code>File.chown</code></a>.</p>
<div class="method-source-code" id="chown-source">
<pre>static VALUE
path_chown(VALUE self, VALUE owner, VALUE group)
{
return rb_funcall(rb_cFile, id_chown, 3, owner, group, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-cleanpath" class="method-detail ">
<div class="method-heading">
<span class="method-name">cleanpath</span><span
class="method-args">(consider_symlink=false)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns clean pathname of <code>self</code> with consecutive slashes and useless dots removed. The filesystem is not accessed.</p>
<p>If <code>consider_symlink</code> is <code>true</code>, then a more conservative algorithm is used to avoid breaking symbolic linkages. This may retain more <code>..</code> entries than absolutely necessary, but without accessing the filesystem, this can't be avoided.</p>
<p>See <a href="Pathname.html#method-i-realpath"><code>Pathname#realpath</code></a>.</p>
<div class="method-source-code" id="cleanpath-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 85</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cleanpath</span>(<span class="ruby-identifier">consider_symlink</span>=<span class="ruby-keyword">false</span>)
<span class="ruby-keyword">if</span> <span class="ruby-identifier">consider_symlink</span>
<span class="ruby-identifier">cleanpath_conservative</span>
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">cleanpath_aggressive</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-ctime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ctime → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the last change time, using directory information, not the file itself.</p>
<p>See <a href="File.html#method-c-ctime"><code>File.ctime</code></a>.</p>
<div class="method-source-code" id="ctime-source">
<pre>static VALUE
path_ctime(VALUE self)
{
return rb_funcall(rb_cFile, id_ctime, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-delete" class="method-detail ">
<div class="method-heading">
<span class="method-name">delete</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Removes a file or directory, using <a href="File.html#method-c-unlink"><code>File.unlink</code></a> if <code>self</code> is a file, or <a href="Dir.html#method-c-unlink"><code>Dir.unlink</code></a> as necessary.</p>
<div class="method-source-code" id="delete-source">
<pre>static VALUE
path_unlink(VALUE self)
{
VALUE eENOTDIR = rb_const_get_at(rb_mErrno, id_ENOTDIR);
VALUE str = get_strpath(self);
return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
}</pre>
</div>
</div>
</div>
<div id="method-i-descend" class="method-detail ">
<div class="method-heading">
<span class="method-name">descend</span><span
class="method-args">() { |v| ... }</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over and yields a new <a href="Pathname.html"><code>Pathname</code></a> object for each element in the given path in descending order.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/path/to/some/file.rb'</span>).<span class="ruby-identifier">descend</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">v</span>}
<span class="ruby-comment">#<Pathname:/></span>
<span class="ruby-comment">#<Pathname:/path></span>
<span class="ruby-comment">#<Pathname:/path/to></span>
<span class="ruby-comment">#<Pathname:/path/to/some></span>
<span class="ruby-comment">#<Pathname:/path/to/some/file.rb></span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'path/to/some/file.rb'</span>).<span class="ruby-identifier">descend</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">v</span>}
<span class="ruby-comment">#<Pathname:path></span>
<span class="ruby-comment">#<Pathname:path/to></span>
<span class="ruby-comment">#<Pathname:path/to/some></span>
<span class="ruby-comment">#<Pathname:path/to/some/file.rb></span>
</pre>
<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block was given.</p>
<pre>enum = Pathname.new("/usr/bin/ruby").descend
# ... do stuff ...
enum.each { |e| ... }
# yields Pathnames /, /usr, /usr/bin, and /usr/bin/ruby.</pre>
<p>It doesn't access the filesystem.</p>
<div class="method-source-code" id="descend-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 292</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">descend</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
<span class="ruby-identifier">vs</span> = []
<span class="ruby-identifier">ascend</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">vs</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">v</span> }
<span class="ruby-identifier">vs</span>.<span class="ruby-identifier">reverse_each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">v</span> }
<span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-directory-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">directory?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-directory-3F"><code>FileTest.directory?</code></a>.</p>
<div class="method-source-code" id="directory-3F-source">
<pre>static VALUE
path_directory_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_directory_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-dirname" class="method-detail ">
<div class="method-heading">
<span class="method-name">dirname</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns all but the last component of the path.</p>
<p>See <a href="File.html#method-c-dirname"><code>File.dirname</code></a>.</p>
<div class="method-source-code" id="dirname-source">
<pre>static VALUE
path_dirname(VALUE self)
{
VALUE str = get_strpath(self);
str = rb_funcall(rb_cFile, id_dirname, 1, str);
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-each_child" class="method-detail ">
<div class="method-heading">
<span class="method-name">each_child</span><span
class="method-args">(with_directory=true, &b)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over the children of the directory (files and subdirectories, not recursive).</p>
<p>It yields <a href="Pathname.html"><code>Pathname</code></a> object for each child.</p>
<p>By default, the yielded pathnames will have enough information to access the files.</p>
<p>If you set <code>with_directory</code> to <code>false</code>, then the returned pathnames will contain the filename only.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>(<span class="ruby-string">"/usr/local"</span>).<span class="ruby-identifier">each_child</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span> }
<span class="ruby-comment">#=> #<Pathname:/usr/local/share></span>
<span class="ruby-comment"># #<Pathname:/usr/local/bin></span>
<span class="ruby-comment"># #<Pathname:/usr/local/games></span>
<span class="ruby-comment"># #<Pathname:/usr/local/lib></span>
<span class="ruby-comment"># #<Pathname:/usr/local/include></span>
<span class="ruby-comment"># #<Pathname:/usr/local/sbin></span>
<span class="ruby-comment"># #<Pathname:/usr/local/src></span>
<span class="ruby-comment"># #<Pathname:/usr/local/man></span>
<span class="ruby-constant">Pathname</span>(<span class="ruby-string">"/usr/local"</span>).<span class="ruby-identifier">each_child</span>(<span class="ruby-keyword">false</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span> }
<span class="ruby-comment">#=> #<Pathname:share></span>
<span class="ruby-comment"># #<Pathname:bin></span>
<span class="ruby-comment"># #<Pathname:games></span>
<span class="ruby-comment"># #<Pathname:lib></span>
<span class="ruby-comment"># #<Pathname:include></span>
<span class="ruby-comment"># #<Pathname:sbin></span>
<span class="ruby-comment"># #<Pathname:src></span>
<span class="ruby-comment"># #<Pathname:man></span>
</pre>
<p>Note that the results never contain the entries <code>.</code> and <code>..</code> in the directory because they are not children.</p>
<p>See <a href="Pathname.html#method-i-children"><code>Pathname#children</code></a></p>
<div class="method-source-code" id="each_child-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 490</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_child</span>(<span class="ruby-identifier">with_directory</span>=<span class="ruby-keyword">true</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
<span class="ruby-identifier">children</span>(<span class="ruby-identifier">with_directory</span>).<span class="ruby-identifier">each</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-each_entry" class="method-detail ">
<div class="method-heading">
<span class="method-name">each_entry</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over the entries (files and subdirectories) in the directory, yielding a <a href="Pathname.html"><code>Pathname</code></a> object for each entry.</p>
<div class="method-source-code" id="each_entry-source">
<pre>static VALUE
path_each_entry(VALUE self)
{
VALUE args[1];
args[0] = get_strpath(self);
return rb_block_call(rb_cDir, id_foreach, 1, args, each_entry_i, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-each_filename" class="method-detail ">
<div class="method-heading">
<span class="method-name">each_filename</span><span
class="method-args">() { |filename| ... }</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over each component of the path.</p>
<pre>Pathname.new("/usr/bin/ruby").each_filename {|filename| ... }
# yields "usr", "bin", and "ruby".</pre>
<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block was given.</p>
<pre>enum = Pathname.new("/usr/bin/ruby").each_filename
# ... do stuff ...
enum.each { |e| ... }
# yields "usr", "bin", and "ruby".</pre>
<div class="method-source-code" id="each_filename-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 260</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_filename</span> <span class="ruby-comment"># :yield: filename</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
<span class="ruby-identifier">_</span>, <span class="ruby-identifier">names</span> = <span class="ruby-identifier">split_names</span>(<span class="ruby-ivar">@path</span>)
<span class="ruby-identifier">names</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">filename</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">filename</span> }
<span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-each_line" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
each_line {|line| ... }
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
each_line(sep=$/ [, open_args]) {|line| block } → nil
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
each_line(limit [, open_args]) {|line| block } → nil
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
each_line(sep, limit [, open_args]) {|line| block } → nil
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
each_line(...) → an_enumerator
</span>
</div>
<div class="method-description">
<p>Iterates over each line in the file and yields a <a href="String.html"><code>String</code></a> object for each.</p>
<div class="method-source-code" id="each_line-source">
<pre>static VALUE
path_each_line(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
if (rb_block_given_p()) {
return rb_block_call_kw(rb_cFile, id_foreach, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
}
else {
return rb_funcallv_kw(rb_cFile, id_foreach, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}
}</pre>
</div>
</div>
</div>
<div id="method-i-empty-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">empty?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Tests the file is empty.</p>
<p>See Dir#empty? and <a href="FileTest.html#method-i-empty-3F"><code>FileTest.empty?</code></a>.</p>
<div class="method-source-code" id="empty-3F-source">
<pre>static VALUE
path_empty_p(VALUE self)
{
VALUE path = get_strpath(self);
if (RTEST(rb_funcall(rb_mFileTest, id_directory_p, 1, path)))
return rb_funcall(rb_cDir, id_empty_p, 1, path);
else
return rb_funcall(rb_mFileTest, id_empty_p, 1, path);
}</pre>
</div>
</div>
</div>
<div id="method-i-entries" class="method-detail ">
<div class="method-heading">
<span class="method-name">entries</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return the entries (files and subdirectories) in the directory, each as a <a href="Pathname.html"><code>Pathname</code></a> object.</p>
<p>The results contains just the names in the directory, without any trailing slashes or recursive look-up.</p>
<pre class="ruby"><span class="ruby-identifier">pp</span> <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/local'</span>).<span class="ruby-identifier">entries</span>
<span class="ruby-comment">#=> [#<Pathname:share>,</span>
<span class="ruby-comment"># #<Pathname:lib>,</span>
<span class="ruby-comment"># #<Pathname:..>,</span>
<span class="ruby-comment"># #<Pathname:include>,</span>
<span class="ruby-comment"># #<Pathname:etc>,</span>
<span class="ruby-comment"># #<Pathname:bin>,</span>
<span class="ruby-comment"># #<Pathname:man>,</span>
<span class="ruby-comment"># #<Pathname:games>,</span>
<span class="ruby-comment"># #<Pathname:.>,</span>
<span class="ruby-comment"># #<Pathname:sbin>,</span>
<span class="ruby-comment"># #<Pathname:src>]</span>
</pre>
<p>The result may contain the current directory <code>#<Pathname:.></code> and the parent directory <code>#<Pathname:..></code>.</p>
<p>If you don't want <code>.</code> and <code>..</code> and want directories, consider <a href="Pathname.html#method-i-children"><code>Pathname#children</code></a>.</p>
<div class="method-source-code" id="entries-source">
<pre>static VALUE
path_entries(VALUE self)
{
VALUE klass, str, ary;
long i;
klass = rb_obj_class(self);
str = get_strpath(self);
ary = rb_funcall(rb_cDir, id_entries, 1, str);
ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
for (i = 0; i < RARRAY_LEN(ary); i++) {
VALUE elt = RARRAY_AREF(ary, i);
elt = rb_class_new_instance(1, &elt, klass);
rb_ary_store(ary, i, elt);
}
return ary;
}</pre>
</div>
</div>
</div>
<div id="method-i-eql-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">eql?</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Compare this pathname with <code>other</code>. The comparison is string-based. Be aware that two different paths (<code>foo.txt</code> and <code>./foo.txt</code>) can refer to the same file.</p>
<div class="method-source-code" id="eql-3F-source">
<pre>static VALUE
path_eq(VALUE self, VALUE other)
{
if (!rb_obj_is_kind_of(other, rb_cPathname))
return Qfalse;
return rb_str_equal(get_strpath(self), get_strpath(other));
}</pre>
</div>
</div>
</div>
<div id="method-i-executable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">executable?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-executable-3F"><code>FileTest.executable?</code></a>.</p>
<div class="method-source-code" id="executable-3F-source">
<pre>static VALUE
path_executable_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_executable_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-executable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">executable_real?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-executable_real-3F"><code>FileTest.executable_real?</code></a>.</p>
<div class="method-source-code" id="executable_real-3F-source">
<pre>static VALUE
path_executable_real_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_executable_real_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-exist-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">exist?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-exist-3F"><code>FileTest.exist?</code></a>.</p>
<div class="method-source-code" id="exist-3F-source">
<pre>static VALUE
path_exist_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_exist_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-expand_path" class="method-detail ">
<div class="method-heading">
<span class="method-name">expand_path</span><span
class="method-args">(p1 = v1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the absolute path for the file.</p>
<p>See <a href="File.html#method-c-expand_path"><code>File.expand_path</code></a>.</p>
<div class="method-source-code" id="expand_path-source">
<pre>static VALUE
path_expand_path(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
VALUE dname;
if (rb_scan_args(argc, argv, "01", &dname) == 0)
str = rb_funcall(rb_cFile, id_expand_path, 1, str);
else
str = rb_funcall(rb_cFile, id_expand_path, 2, str, dname);
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-extname" class="method-detail ">
<div class="method-heading">
<span class="method-name">extname</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the file's extension.</p>
<p>See <a href="File.html#method-c-extname"><code>File.extname</code></a>.</p>
<div class="method-source-code" id="extname-source">
<pre>static VALUE
path_extname(VALUE self)
{
VALUE str = get_strpath(self);
return rb_funcall(rb_cFile, id_extname, 1, str);
}</pre>
</div>
</div>
</div>
<div id="method-i-file-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">file?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-file-3F"><code>FileTest.file?</code></a>.</p>
<div class="method-source-code" id="file-3F-source">
<pre>static VALUE
path_file_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_file_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-find" class="method-detail ">
<div class="method-heading">
<span class="method-name">find</span><span
class="method-args">(ignore_error: true) { |pathname| ... }</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Iterates over the directory tree in a depth first manner, yielding a <a href="Pathname.html"><code>Pathname</code></a> for each file under “this” directory.</p>
<p>Returns an <a href="Enumerator.html"><code>Enumerator</code></a> if no block is given.</p>
<p>Since it is implemented by the standard library module <a href="Find.html"><code>Find</code></a>, <a href="Find.html#method-c-prune"><code>Find.prune</code></a> can be used to control the traversal.</p>
<p>If <code>self</code> is <code>.</code>, yielded pathnames begin with a filename in the current directory, not <code>./</code>.</p>
<p>See <a href="Find.html#method-c-find"><code>Find.find</code></a></p>
<div class="method-source-code" id="find-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 559</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">find</span>(<span class="ruby-value">ignore_error:</span> <span class="ruby-keyword">true</span>) <span class="ruby-comment"># :yield: pathname</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>, <span class="ruby-value">ignore_error:</span> <span class="ruby-identifier">ignore_error</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">block_given?</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">'find'</span>
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@path</span> <span class="ruby-operator">==</span> <span class="ruby-string">'.'</span>
<span class="ruby-constant">Find</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-value">ignore_error:</span> <span class="ruby-identifier">ignore_error</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">f</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">%r{\A\./}</span>, <span class="ruby-string">''</span>)) }
<span class="ruby-keyword">else</span>
<span class="ruby-constant">Find</span>.<span class="ruby-identifier">find</span>(<span class="ruby-ivar">@path</span>, <span class="ruby-value">ignore_error:</span> <span class="ruby-identifier">ignore_error</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">f</span>) }
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-fnmatch" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
fnmatch(pattern, [flags]) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
fnmatch?(pattern, [flags]) → string
</span>
</div>
<div class="method-description">
<p>Return <code>true</code> if the receiver matches the given pattern.</p>
<p>See <a href="File.html#method-c-fnmatch"><code>File.fnmatch</code></a>.</p>
<div class="method-source-code" id="fnmatch-source">
<pre>static VALUE
path_fnmatch(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
VALUE pattern, flags;
if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
return rb_funcall(rb_cFile, id_fnmatch, 2, pattern, str);
else
return rb_funcall(rb_cFile, id_fnmatch, 3, pattern, str, flags);
}</pre>
</div>
</div>
</div>
<div id="method-i-fnmatch-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
fnmatch?(pattern, [flags]) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return <code>true</code> if the receiver matches the given pattern.</p>
<p>See <a href="File.html#method-c-fnmatch"><code>File.fnmatch</code></a>.</p>
<div class="method-source-code" id="fnmatch-3F-source">
<pre>static VALUE
path_fnmatch(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
VALUE pattern, flags;
if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
return rb_funcall(rb_cFile, id_fnmatch, 2, pattern, str);
else
return rb_funcall(rb_cFile, id_fnmatch, 3, pattern, str, flags);
}</pre>
</div>
</div>
</div>
<div id="method-i-freeze" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
freeze → obj
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Freezes this <a href="Pathname.html"><code>Pathname</code></a>.</p>
<p>See <a href="Object.html#method-i-freeze"><code>Object.freeze</code></a>.</p>
<div class="method-source-code" id="freeze-source">
<pre>static VALUE
path_freeze(VALUE self)
{
rb_call_super(0, 0);
rb_str_freeze(get_strpath(self));
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-ftype" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
ftype → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns “type” of file (“file”, “directory”, etc).</p>
<p>See <a href="File.html#method-c-ftype"><code>File.ftype</code></a>.</p>
<div class="method-source-code" id="ftype-source">
<pre>static VALUE
path_ftype(VALUE self)
{
return rb_funcall(rb_cFile, id_ftype, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-glob" class="method-detail ">
<div class="method-heading">
<span class="method-name">glob</span><span
class="method-args">(p1, p2 = v2)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns or yields <a href="Pathname.html"><code>Pathname</code></a> objects.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>(<span class="ruby-string">"ruby-2.4.2"</span>).<span class="ruby-identifier">glob</span>(<span class="ruby-string">"R*.md"</span>)
<span class="ruby-comment">#=> [#<Pathname:ruby-2.4.2/README.md>, #<Pathname:ruby-2.4.2/README.ja.md>]</span>
</pre>
<p>See <a href="Dir.html#method-c-glob"><code>Dir.glob</code></a>. This method uses the <code>base</code> keyword argument of <a href="Dir.html#method-c-glob"><code>Dir.glob</code></a>.</p>
<div class="method-source-code" id="glob-source">
<pre>static VALUE
path_glob(int argc, VALUE *argv, VALUE self)
{
VALUE args[3];
int n;
n = rb_scan_args(argc, argv, "11", &args[0], &args[1]);
if (n == 1)
args[1] = INT2FIX(0);
args[2] = rb_hash_new();
rb_hash_aset(args[2], ID2SYM(id_base), get_strpath(self));
n = 3;
if (rb_block_given_p()) {
return rb_block_call_kw(rb_cDir, id_glob, n, args, glob_i, self, RB_PASS_KEYWORDS);
}
else {
VALUE ary;
long i;
ary = rb_funcallv_kw(rb_cDir, id_glob, n, args, RB_PASS_KEYWORDS);
ary = rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
for (i = 0; i < RARRAY_LEN(ary); i++) {
VALUE elt = RARRAY_AREF(ary, i);
elt = rb_funcall(self, '+', 1, elt);
rb_ary_store(ary, i, elt);
}
return ary;
}
}</pre>
</div>
</div>
</div>
<div id="method-i-grpowned-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">grpowned?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-grpowned-3F"><code>FileTest.grpowned?</code></a>.</p>
<div class="method-source-code" id="grpowned-3F-source">
<pre>static VALUE
path_grpowned_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_grpowned_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-join" class="method-detail ">
<div class="method-heading">
<span class="method-name">join</span><span
class="method-args">(*args)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Joins the given pathnames onto <code>self</code> to create a new <a href="Pathname.html"><code>Pathname</code></a> object.</p>
<pre class="ruby"><span class="ruby-identifier">path0</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"/usr"</span>) <span class="ruby-comment"># Pathname:/usr</span>
<span class="ruby-identifier">path0</span> = <span class="ruby-identifier">path0</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">"bin/ruby"</span>) <span class="ruby-comment"># Pathname:/usr/bin/ruby</span>
<span class="ruby-comment"># is the same as</span>
<span class="ruby-identifier">path1</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">"/usr"</span>) <span class="ruby-operator">+</span> <span class="ruby-string">"bin/ruby"</span> <span class="ruby-comment"># Pathname:/usr/bin/ruby</span>
<span class="ruby-identifier">path0</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">path1</span>
<span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="join-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 407</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">join</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
<span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span>
<span class="ruby-identifier">result</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">result</span>) <span class="ruby-keyword">unless</span> <span class="ruby-constant">Pathname</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">result</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">result</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">absolute?</span>
<span class="ruby-identifier">args</span>.<span class="ruby-identifier">reverse_each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">arg</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arg</span>) <span class="ruby-keyword">unless</span> <span class="ruby-constant">Pathname</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">arg</span>
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">arg</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">result</span>
<span class="ruby-keyword">return</span> <span class="ruby-identifier">result</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">absolute?</span>
}
<span class="ruby-keyword">self</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-lchmod" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
lchmod → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Same as <a href="Pathname.html#method-i-chmod"><code>Pathname.chmod</code></a>, but does not follow symbolic links.</p>
<p>See <a href="File.html#method-c-lchmod"><code>File.lchmod</code></a>.</p>
<div class="method-source-code" id="lchmod-source">
<pre>static VALUE
path_lchmod(VALUE self, VALUE mode)
{
return rb_funcall(rb_cFile, id_lchmod, 2, mode, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-lchown" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
lchown → integer
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Same as <a href="Pathname.html#method-i-chown"><code>Pathname.chown</code></a>, but does not follow symbolic links.</p>
<p>See <a href="File.html#method-c-lchown"><code>File.lchown</code></a>.</p>
<div class="method-source-code" id="lchown-source">
<pre>static VALUE
path_lchown(VALUE self, VALUE owner, VALUE group)
{
return rb_funcall(rb_cFile, id_lchown, 3, owner, group, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-lstat" class="method-detail ">
<div class="method-heading">
<span class="method-name">lstat</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="File.html#method-c-lstat"><code>File.lstat</code></a>.</p>
<div class="method-source-code" id="lstat-source">
<pre>static VALUE
path_lstat(VALUE self)
{
return rb_funcall(rb_cFile, id_lstat, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-make_link" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
make_link(old)
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a hard link at <em>pathname</em>.</p>
<p>See <a href="File.html#method-c-link"><code>File.link</code></a>.</p>
<div class="method-source-code" id="make_link-source">
<pre>static VALUE
path_make_link(VALUE self, VALUE old)
{
return rb_funcall(rb_cFile, id_link, 2, old, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-make_symlink" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
make_symlink(old)
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a symbolic link.</p>
<p>See <a href="File.html#method-c-symlink"><code>File.symlink</code></a>.</p>
<div class="method-source-code" id="make_symlink-source">
<pre>static VALUE
path_make_symlink(VALUE self, VALUE old)
{
return rb_funcall(rb_cFile, id_symlink, 2, old, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-mkdir" class="method-detail ">
<div class="method-heading">
<span class="method-name">mkdir</span><span
class="method-args">(p1 = v1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Create the referenced directory.</p>
<p>See <a href="Dir.html#method-c-mkdir"><code>Dir.mkdir</code></a>.</p>
<div class="method-source-code" id="mkdir-source">
<pre>static VALUE
path_mkdir(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
VALUE vmode;
if (rb_scan_args(argc, argv, "01", &vmode) == 0)
return rb_funcall(rb_cDir, id_mkdir, 1, str);
else
return rb_funcall(rb_cDir, id_mkdir, 2, str, vmode);
}</pre>
</div>
</div>
</div>
<div id="method-i-mkpath" class="method-detail ">
<div class="method-heading">
<span class="method-name">mkpath</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a full path, including any intermediate directories that don't yet exist.</p>
<p>See <a href="FileUtils.html#method-c-mkpath"><code>FileUtils.mkpath</code></a> and <a href="FileUtils.html#method-c-mkdir_p"><code>FileUtils.mkdir_p</code></a></p>
<div class="method-source-code" id="mkpath-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 576</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mkpath</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">'fileutils'</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkpath</span>(<span class="ruby-ivar">@path</span>)
<span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-mountpoint-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">mountpoint?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns <code>true</code> if <code>self</code> points to a mountpoint.</p>
<div class="method-source-code" id="mountpoint-3F-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 192</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">mountpoint?</span>
<span class="ruby-keyword">begin</span>
<span class="ruby-identifier">stat1</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">lstat</span>
<span class="ruby-identifier">stat2</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">lstat</span>
<span class="ruby-identifier">stat1</span>.<span class="ruby-identifier">dev</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">stat2</span>.<span class="ruby-identifier">dev</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">stat1</span>.<span class="ruby-identifier">ino</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">stat2</span>.<span class="ruby-identifier">ino</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span>
<span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-mtime" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
mtime → time
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the last modified time of the file.</p>
<p>See <a href="File.html#method-c-mtime"><code>File.mtime</code></a>.</p>
<div class="method-source-code" id="mtime-source">
<pre>static VALUE
path_mtime(VALUE self)
{
return rb_funcall(rb_cFile, id_mtime, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-open" class="method-detail ">
<div class="method-heading">
<span class="method-name">open</span><span
class="method-args">(p1 = v1, p2 = v2, p3 = v3)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Opens the file for reading or writing.</p>
<p>See <a href="File.html#method-c-open"><code>File.open</code></a>.</p>
<div class="method-source-code" id="open-source">
<pre>static VALUE
path_open(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
if (rb_block_given_p()) {
return rb_block_call_kw(rb_cFile, id_open, 1+n, args, 0, 0, RB_PASS_CALLED_KEYWORDS);
}
else {
return rb_funcallv_kw(rb_cFile, id_open, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}
}</pre>
</div>
</div>
</div>
<div id="method-i-opendir" class="method-detail ">
<div class="method-heading">
<span class="method-name">opendir</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Opens the referenced directory.</p>
<p>See <a href="Dir.html#method-c-open"><code>Dir.open</code></a>.</p>
<div class="method-source-code" id="opendir-source">
<pre>static VALUE
path_opendir(VALUE self)
{
VALUE args[1];
args[0] = get_strpath(self);
return rb_block_call(rb_cDir, id_open, 1, args, 0, 0);
}</pre>
</div>
</div>
</div>
<div id="method-i-owned-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">owned?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-owned-3F"><code>FileTest.owned?</code></a>.</p>
<div class="method-source-code" id="owned-3F-source">
<pre>static VALUE
path_owned_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_owned_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-parent" class="method-detail ">
<div class="method-heading">
<span class="method-name">parent</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the parent directory.</p>
<p>This is same as <code>self + '..'</code>.</p>
<div class="method-source-code" id="parent-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 187</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parent</span>
<span class="ruby-keyword">self</span> <span class="ruby-operator">+</span> <span class="ruby-string">'..'</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-pipe-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">pipe?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-pipe-3F"><code>FileTest.pipe?</code></a>.</p>
<div class="method-source-code" id="pipe-3F-source">
<pre>static VALUE
path_pipe_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_pipe_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-read" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
read([length [, offset]]) → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
read([length [, offset]], open_args) → string
</span>
</div>
<div class="method-description">
<p>Returns all data from the file, or the first <code>N</code> bytes if specified.</p>
<p>See <a href="IO.html#method-c-read"><code>File.read</code></a>.</p>
<div class="method-source-code" id="read-source">
<pre>static VALUE
path_read(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
return rb_funcallv_kw(rb_cFile, id_read, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}</pre>
</div>
</div>
</div>
<div id="method-i-readable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">readable?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-readable-3F"><code>FileTest.readable?</code></a>.</p>
<div class="method-source-code" id="readable-3F-source">
<pre>static VALUE
path_readable_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_readable_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-readable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">readable_real?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-readable_real-3F"><code>FileTest.readable_real?</code></a>.</p>
<div class="method-source-code" id="readable_real-3F-source">
<pre>static VALUE
path_readable_real_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_readable_real_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-readlines" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
readlines(sep=$/ [, open_args]) → array
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
readlines(limit [, open_args]) → array
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
readlines(sep, limit [, open_args]) → array
</span>
</div>
<div class="method-description">
<p>Returns all the lines from the file.</p>
<p>See <a href="IO.html#method-c-readlines"><code>File.readlines</code></a>.</p>
<div class="method-source-code" id="readlines-source">
<pre>static VALUE
path_readlines(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
return rb_funcallv_kw(rb_cFile, id_readlines, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}</pre>
</div>
</div>
</div>
<div id="method-i-readlink" class="method-detail ">
<div class="method-heading">
<span class="method-name">readlink</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Read symbolic link.</p>
<p>See <a href="File.html#method-c-readlink"><code>File.readlink</code></a>.</p>
<div class="method-source-code" id="readlink-source">
<pre>static VALUE
path_readlink(VALUE self)
{
VALUE str;
str = rb_funcall(rb_cFile, id_readlink, 1, get_strpath(self));
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-realdirpath" class="method-detail ">
<div class="method-heading">
<span class="method-name">realdirpath</span><span
class="method-args">(p1 = v1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the real (absolute) pathname of <code>self</code> in the actual filesystem.</p>
<p>Does not contain symlinks or useless dots, <code>..</code> and <code>.</code>.</p>
<p>The last component of the real pathname can be nonexistent.</p>
<div class="method-source-code" id="realdirpath-source">
<pre>static VALUE
path_realdirpath(int argc, VALUE *argv, VALUE self)
{
VALUE basedir, str;
rb_scan_args(argc, argv, "01", &basedir);
str = rb_funcall(rb_cFile, id_realdirpath, 2, get_strpath(self), basedir);
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-realpath" class="method-detail ">
<div class="method-heading">
<span class="method-name">realpath</span><span
class="method-args">(p1 = v1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the real (absolute) pathname for <code>self</code> in the actual filesystem.</p>
<p>Does not contain symlinks or useless dots, <code>..</code> and <code>.</code>.</p>
<p>All components of the pathname must exist when this method is called.</p>
<div class="method-source-code" id="realpath-source">
<pre>static VALUE
path_realpath(int argc, VALUE *argv, VALUE self)
{
VALUE basedir, str;
rb_scan_args(argc, argv, "01", &basedir);
str = rb_funcall(rb_cFile, id_realpath, 2, get_strpath(self), basedir);
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-relative-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">relative?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>The opposite of <a href="Pathname.html#method-i-absolute-3F"><code>Pathname#absolute?</code></a></p>
<p>It returns <code>false</code> if the pathname begins with a slash.</p>
<pre class="ruby"><span class="ruby-identifier">p</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/im/sure'</span>)
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">relative?</span>
<span class="ruby-comment">#=> false</span>
<span class="ruby-identifier">p</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'not/so/sure'</span>)
<span class="ruby-identifier">p</span>.<span class="ruby-identifier">relative?</span>
<span class="ruby-comment">#=> true</span>
</pre>
<div class="method-source-code" id="relative-3F-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 239</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">relative?</span>
<span class="ruby-identifier">path</span> = <span class="ruby-ivar">@path</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">chop_basename</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">path</span>, = <span class="ruby-identifier">r</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">path</span> <span class="ruby-operator">==</span> <span class="ruby-string">''</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-relative_path_from" class="method-detail ">
<div class="method-heading">
<span class="method-name">relative_path_from</span><span
class="method-args">(base_directory)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a relative path from the given <code>base_directory</code> to the receiver.</p>
<p>If <code>self</code> is absolute, then <code>base_directory</code> must be absolute too.</p>
<p>If <code>self</code> is relative, then <code>base_directory</code> must be relative too.</p>
<p>This method doesn't access the filesystem. It assumes no symlinks.</p>
<p><a href="ArgumentError.html"><code>ArgumentError</code></a> is raised when it cannot find a relative path.</p>
<div class="method-source-code" id="relative_path_from-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 505</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">relative_path_from</span>(<span class="ruby-identifier">base_directory</span>)
<span class="ruby-identifier">base_directory</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">base_directory</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">base_directory</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Pathname</span>
<span class="ruby-identifier">dest_directory</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">cleanpath</span>.<span class="ruby-identifier">to_s</span>
<span class="ruby-identifier">base_directory</span> = <span class="ruby-identifier">base_directory</span>.<span class="ruby-identifier">cleanpath</span>.<span class="ruby-identifier">to_s</span>
<span class="ruby-identifier">dest_prefix</span> = <span class="ruby-identifier">dest_directory</span>
<span class="ruby-identifier">dest_names</span> = []
<span class="ruby-keyword">while</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">chop_basename</span>(<span class="ruby-identifier">dest_prefix</span>)
<span class="ruby-identifier">dest_prefix</span>, <span class="ruby-identifier">basename</span> = <span class="ruby-identifier">r</span>
<span class="ruby-identifier">dest_names</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">basename</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">basename</span> <span class="ruby-operator">!=</span> <span class="ruby-string">'.'</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">base_prefix</span> = <span class="ruby-identifier">base_directory</span>
<span class="ruby-identifier">base_names</span> = []
<span class="ruby-keyword">while</span> <span class="ruby-identifier">r</span> = <span class="ruby-identifier">chop_basename</span>(<span class="ruby-identifier">base_prefix</span>)
<span class="ruby-identifier">base_prefix</span>, <span class="ruby-identifier">basename</span> = <span class="ruby-identifier">r</span>
<span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">basename</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">basename</span> <span class="ruby-operator">!=</span> <span class="ruby-string">'.'</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">unless</span> <span class="ruby-constant">SAME_PATHS</span>[<span class="ruby-identifier">dest_prefix</span>, <span class="ruby-identifier">base_prefix</span>]
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"different prefix: #{dest_prefix.inspect} and #{base_directory.inspect}"</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">while</span> <span class="ruby-operator">!</span><span class="ruby-identifier">dest_names</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&&</span>
<span class="ruby-operator">!</span><span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&&</span>
<span class="ruby-constant">SAME_PATHS</span>[<span class="ruby-identifier">dest_names</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">first</span>]
<span class="ruby-identifier">dest_names</span>.<span class="ruby-identifier">shift</span>
<span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">shift</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">if</span> <span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">include?</span> <span class="ruby-string">'..'</span>
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"base_directory has ..: #{base_directory.inspect}"</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">base_names</span>.<span class="ruby-identifier">fill</span>(<span class="ruby-string">'..'</span>)
<span class="ruby-identifier">relpath_names</span> = <span class="ruby-identifier">base_names</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">dest_names</span>
<span class="ruby-keyword">if</span> <span class="ruby-identifier">relpath_names</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'.'</span>)
<span class="ruby-keyword">else</span>
<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">relpath_names</span>))
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-rename" class="method-detail ">
<div class="method-heading">
<span class="method-name">rename</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Rename the file.</p>
<p>See <a href="File.html#method-c-rename"><code>File.rename</code></a>.</p>
<div class="method-source-code" id="rename-source">
<pre>static VALUE
path_rename(VALUE self, VALUE to)
{
return rb_funcall(rb_cFile, id_rename, 2, get_strpath(self), to);
}</pre>
</div>
</div>
</div>
<div id="method-i-rmdir" class="method-detail ">
<div class="method-heading">
<span class="method-name">rmdir</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Remove the referenced directory.</p>
<p>See <a href="Dir.html#method-c-rmdir"><code>Dir.rmdir</code></a>.</p>
<div class="method-source-code" id="rmdir-source">
<pre>static VALUE
path_rmdir(VALUE self)
{
return rb_funcall(rb_cDir, id_rmdir, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-rmtree" class="method-detail ">
<div class="method-heading">
<span class="method-name">rmtree</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Recursively deletes a directory, including all directories beneath it.</p>
<p>See <a href="FileUtils.html#method-c-rm_r"><code>FileUtils.rm_r</code></a></p>
<div class="method-source-code" id="rmtree-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 585</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">rmtree</span>
<span class="ruby-comment"># The name "rmtree" is borrowed from File::Path of Perl.</span>
<span class="ruby-comment"># File::Path provides "mkpath" and "rmtree".</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">'fileutils'</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_r</span>(<span class="ruby-ivar">@path</span>)
<span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-root-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">root?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Predicate method for root directories. Returns <code>true</code> if the pathname consists of consecutive slashes.</p>
<p>It doesn't access the filesystem. So it may return <code>false</code> for some pathnames which points to roots such as <code>/usr/..</code>.</p>
<div class="method-source-code" id="root-3F-source">
<pre><span class="ruby-comment"># File ext/pathname/lib/pathname.rb, line 209</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">root?</span>
<span class="ruby-identifier">chop_basename</span>(<span class="ruby-ivar">@path</span>) <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-regexp">/#{SEPARATOR_PAT}/o</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-ivar">@path</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-i-setgid-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">setgid?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-setgid-3F"><code>FileTest.setgid?</code></a>.</p>
<div class="method-source-code" id="setgid-3F-source">
<pre>static VALUE
path_setgid_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_setgid_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-setuid-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">setuid?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-setuid-3F"><code>FileTest.setuid?</code></a>.</p>
<div class="method-source-code" id="setuid-3F-source">
<pre>static VALUE
path_setuid_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_setuid_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-size" class="method-detail ">
<div class="method-heading">
<span class="method-name">size</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-size"><code>FileTest.size</code></a>.</p>
<div class="method-source-code" id="size-source">
<pre>static VALUE
path_size(VALUE self)
{
return rb_funcall(rb_mFileTest, id_size, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-size-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">size?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-size-3F"><code>FileTest.size?</code></a>.</p>
<div class="method-source-code" id="size-3F-source">
<pre>static VALUE
path_size_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_size_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-socket-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">socket?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-socket-3F"><code>FileTest.socket?</code></a>.</p>
<div class="method-source-code" id="socket-3F-source">
<pre>static VALUE
path_socket_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_socket_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-split" class="method-detail ">
<div class="method-heading">
<span class="method-name">split</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the <a href="Pathname.html#method-i-dirname"><code>dirname</code></a> and the <a href="Pathname.html#method-i-basename"><code>basename</code></a> in an <a href="Array.html"><code>Array</code></a>.</p>
<p>See <a href="File.html#method-c-split"><code>File.split</code></a>.</p>
<div class="method-source-code" id="split-source">
<pre>static VALUE
path_split(VALUE self)
{
VALUE str = get_strpath(self);
VALUE ary, dirname, basename;
ary = rb_funcall(rb_cFile, id_split, 1, str);
ary = rb_check_array_type(ary);
dirname = rb_ary_entry(ary, 0);
basename = rb_ary_entry(ary, 1);
dirname = rb_class_new_instance(1, &dirname, rb_obj_class(self));
basename = rb_class_new_instance(1, &basename, rb_obj_class(self));
return rb_ary_new3(2, dirname, basename);
}</pre>
</div>
</div>
</div>
<div id="method-i-stat" class="method-detail ">
<div class="method-heading">
<span class="method-name">stat</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a <a href="File/Stat.html"><code>File::Stat</code></a> object.</p>
<p>See <a href="File.html#method-c-stat"><code>File.stat</code></a>.</p>
<div class="method-source-code" id="stat-source">
<pre>static VALUE
path_stat(VALUE self)
{
return rb_funcall(rb_cFile, id_stat, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-sticky-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">sticky?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-sticky-3F"><code>FileTest.sticky?</code></a>.</p>
<div class="method-source-code" id="sticky-3F-source">
<pre>static VALUE
path_sticky_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_sticky_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-sub" class="method-detail ">
<div class="method-heading">
<span class="method-name">sub</span><span
class="method-args">(*args)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return a pathname which is substituted by <a href="String.html#method-i-sub"><code>String#sub</code></a>.</p>
<pre class="ruby"><span class="ruby-identifier">path1</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin/perl'</span>)
<span class="ruby-identifier">path1</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-string">'perl'</span>, <span class="ruby-string">'ruby'</span>)
<span class="ruby-comment">#=> #<Pathname:/usr/bin/ruby></span>
</pre>
<div class="method-source-code" id="sub-source">
<pre>static VALUE
path_sub(int argc, VALUE *argv, VALUE self)
{
VALUE str = get_strpath(self);
if (rb_block_given_p()) {
str = rb_block_call(str, id_sub, argc, argv, 0, 0);
}
else {
str = rb_funcallv(str, id_sub, argc, argv);
}
return rb_class_new_instance(1, &str, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-sub_ext" class="method-detail ">
<div class="method-heading">
<span class="method-name">sub_ext</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return a pathname with <code>repl</code> added as a suffix to the basename.</p>
<p>If self has no extension part, <code>repl</code> is appended.</p>
<pre class="ruby"><span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'/usr/bin/shutdown'</span>).<span class="ruby-identifier">sub_ext</span>(<span class="ruby-string">'.rb'</span>)
<span class="ruby-comment">#=> #<Pathname:/usr/bin/shutdown.rb></span>
</pre>
<div class="method-source-code" id="sub_ext-source">
<pre>static VALUE
path_sub_ext(VALUE self, VALUE repl)
{
VALUE str = get_strpath(self);
VALUE str2;
long extlen;
const char *ext;
const char *p;
StringValue(repl);
p = RSTRING_PTR(str);
extlen = RSTRING_LEN(str);
ext = ruby_enc_find_extname(p, &extlen, rb_enc_get(str));
if (ext == NULL) {
ext = p + RSTRING_LEN(str);
}
else if (extlen <= 1) {
ext += extlen;
}
str2 = rb_str_subseq(str, 0, ext-p);
rb_str_append(str2, repl);
return rb_class_new_instance(1, &str2, rb_obj_class(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-symlink-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">symlink?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-symlink-3F"><code>FileTest.symlink?</code></a>.</p>
<div class="method-source-code" id="symlink-3F-source">
<pre>static VALUE
path_symlink_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_symlink_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-sysopen" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
sysopen([mode, [perm]]) → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="IO.html#method-c-sysopen"><code>IO.sysopen</code></a>.</p>
<div class="method-source-code" id="sysopen-source">
<pre>static VALUE
path_sysopen(int argc, VALUE *argv, VALUE self)
{
VALUE args[3];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "02", &args[1], &args[2]);
return rb_funcallv(rb_cIO, id_sysopen, 1+n, args);
}</pre>
</div>
</div>
</div>
<div id="method-i-taint" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
taint → obj
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns pathname. This method is deprecated and will be removed in Ruby 3.2.</p>
<div class="method-source-code" id="taint-source">
<pre>static VALUE
path_taint(VALUE self)
{
rb_warning("Pathname#taint is deprecated and will be removed in Ruby 3.2.");
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-to_path" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_path → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return the path as a <a href="String.html"><code>String</code></a>.</p>
<p><a href="Pathname.html#method-i-to_path"><code>to_path</code></a> is implemented so <a href="Pathname.html"><code>Pathname</code></a> objects are usable with <a href="File.html#method-c-open"><code>File.open</code></a>, etc.</p>
<div class="method-source-code" id="to_path-source">
<pre>static VALUE
path_to_s(VALUE self)
{
return rb_obj_dup(get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-to_s" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
to_s → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return the path as a <a href="String.html"><code>String</code></a>.</p>
<p><a href="Pathname.html#method-i-to_path"><code>to_path</code></a> is implemented so <a href="Pathname.html"><code>Pathname</code></a> objects are usable with <a href="File.html#method-c-open"><code>File.open</code></a>, etc.</p>
<div class="method-source-code" id="to_s-source">
<pre>static VALUE
path_to_s(VALUE self)
{
return rb_obj_dup(get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-truncate" class="method-detail ">
<div class="method-heading">
<span class="method-name">truncate</span><span
class="method-args">(p1)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Truncates the file to <code>length</code> bytes.</p>
<p>See <a href="File.html#method-c-truncate"><code>File.truncate</code></a>.</p>
<div class="method-source-code" id="truncate-source">
<pre>static VALUE
path_truncate(VALUE self, VALUE length)
{
return rb_funcall(rb_cFile, id_truncate, 2, get_strpath(self), length);
}</pre>
</div>
</div>
</div>
<div id="method-i-unlink" class="method-detail ">
<div class="method-heading">
<span class="method-name">unlink</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Removes a file or directory, using <a href="File.html#method-c-unlink"><code>File.unlink</code></a> if <code>self</code> is a file, or <a href="Dir.html#method-c-unlink"><code>Dir.unlink</code></a> as necessary.</p>
<div class="method-source-code" id="unlink-source">
<pre>static VALUE
path_unlink(VALUE self)
{
VALUE eENOTDIR = rb_const_get_at(rb_mErrno, id_ENOTDIR);
VALUE str = get_strpath(self);
return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
}</pre>
</div>
</div>
</div>
<div id="method-i-untaint" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
untaint → obj
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns pathname. This method is deprecated and will be removed in Ruby 3.2.</p>
<div class="method-source-code" id="untaint-source">
<pre>static VALUE
path_untaint(VALUE self)
{
rb_warning("Pathname#untaint is deprecated and will be removed in Ruby 3.2.");
return self;
}</pre>
</div>
</div>
</div>
<div id="method-i-utime" class="method-detail ">
<div class="method-heading">
<span class="method-name">utime</span><span
class="method-args">(p1, p2)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Update the access and modification times of the file.</p>
<p>See <a href="File.html#method-c-utime"><code>File.utime</code></a>.</p>
<div class="method-source-code" id="utime-source">
<pre>static VALUE
path_utime(VALUE self, VALUE atime, VALUE mtime)
{
return rb_funcall(rb_cFile, id_utime, 3, atime, mtime, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-world_readable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">world_readable?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-world_readable-3F"><code>FileTest.world_readable?</code></a>.</p>
<div class="method-source-code" id="world_readable-3F-source">
<pre>static VALUE
path_world_readable_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_world_readable_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-world_writable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">world_writable?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-world_writable-3F"><code>FileTest.world_writable?</code></a>.</p>
<div class="method-source-code" id="world_writable-3F-source">
<pre>static VALUE
path_world_writable_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_world_writable_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-writable-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">writable?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-writable-3F"><code>FileTest.writable?</code></a>.</p>
<div class="method-source-code" id="writable-3F-source">
<pre>static VALUE
path_writable_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_writable_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-writable_real-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">writable_real?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-writable_real-3F"><code>FileTest.writable_real?</code></a>.</p>
<div class="method-source-code" id="writable_real-3F-source">
<pre>static VALUE
path_writable_real_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_writable_real_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
<div id="method-i-write" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
write(string, [offset] ) → fixnum
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
write(string, [offset], open_args ) → fixnum
</span>
</div>
<div class="method-description">
<p>Writes <code>contents</code> to the file.</p>
<p>See <a href="IO.html#method-c-write"><code>File.write</code></a>.</p>
<div class="method-source-code" id="write-source">
<pre>static VALUE
path_write(int argc, VALUE *argv, VALUE self)
{
VALUE args[4];
int n;
args[0] = get_strpath(self);
n = rb_scan_args(argc, argv, "03", &args[1], &args[2], &args[3]);
return rb_funcallv_kw(rb_cFile, id_write, 1+n, args, RB_PASS_CALLED_KEYWORDS);
}</pre>
</div>
</div>
</div>
<div id="method-i-zero-3F" class="method-detail ">
<div class="method-heading">
<span class="method-name">zero?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>See <a href="FileTest.html#method-i-zero-3F"><code>FileTest.zero?</code></a>.</p>
<div class="method-source-code" id="zero-3F-source">
<pre>static VALUE
path_zero_p(VALUE self)
{
return rb_funcall(rb_mFileTest, id_zero_p, 1, get_strpath(self));
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>