File: C:/Ruby27-x64/share/doc/ruby/html/PP.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class PP - 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-PP-label-What+PP+Does">What PP Does</a>
<li><a href="#class-PP-label-Usage">Usage</a>
<li><a href="#class-PP-label-Output+Customization">Output Customization</a>
<li><a href="#class-PP-label-Pretty-Print+JSON">Pretty-Print JSON</a>
<li><a href="#class-PP-label-Author">Author</a>
</ul>
</div>
<div id="class-metadata">
<div id="parent-class-section" class="nav-section">
<h3>Parent</h3>
<p class="link"><a href="PrettyPrint.html">PrettyPrint</a>
</div>
<div id="includes-section" class="nav-section">
<h3>Included Modules</h3>
<ul class="link-list">
<li><a class="include" href="PP/PPMethods.html">PP::PPMethods</a>
</ul>
</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-pp">::pp</a>
<li ><a href="#method-c-singleline_pp">::singleline_pp</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="class-PP">
<h1 id="class-PP" class="class">
class PP
</h1>
<section class="description">
<p>A pretty-printer for Ruby objects.</p>
<h2 id="class-PP-label-What+PP+Does">What <a href="PP.html"><code>PP</code></a> Does<span><a href="#class-PP-label-What+PP+Does">¶</a> <a href="#top">↑</a></span></h2>
<p>Standard output by <a href="Kernel.html#method-i-p"><code>p</code></a> returns this:</p>
<pre class="ruby"><span class="ruby-comment">#<PP:0x81fedf0 @genspace=#<Proc:0x81feda0>, @group_queue=#<PrettyPrint::GroupQueue:0x81fed3c @queue=[[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], []]>, @buffer=[], @newline="\n", @group_stack=[#<PrettyPrint::Group:0x81fed78 @breakables=[], @depth=0, @break=false>], @buffer_width=0, @indent=0, @maxwidth=79, @output_width=2, @output=#<IO:0x8114ee4>></span>
</pre>
<p>Pretty-printed output returns this:</p>
<pre>#<PP:0x81fedf0
@buffer=[],
@buffer_width=0,
@genspace=#<Proc:0x81feda0>,
@group_queue=
#<PrettyPrint::GroupQueue:0x81fed3c
@queue=
[[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
[]]>,
@group_stack=
[#<PrettyPrint::Group:0x81fed78 @break=false, @breakables=[], @depth=0>],
@indent=0,
@maxwidth=79,
@newline="\n",
@output=#<IO:0x8114ee4>,
@output_width=2></pre>
<h2 id="class-PP-label-Usage">Usage<span><a href="#class-PP-label-Usage">¶</a> <a href="#top">↑</a></span></h2>
<pre>pp(obj) #=> obj
pp obj #=> obj
pp(obj1, obj2, ...) #=> [obj1, obj2, ...]
pp() #=> nil</pre>
<p>Output <code>obj(s)</code> to <code>$></code> in pretty printed format.</p>
<p>It returns <code>obj(s)</code>.</p>
<h2 id="class-PP-label-Output+Customization">Output Customization<span><a href="#class-PP-label-Output+Customization">¶</a> <a href="#top">↑</a></span></h2>
<p>To define a customized pretty printing function for your classes, redefine method <code>#pretty_print(pp)</code> in the class.</p>
<p><code>#pretty_print</code> takes the <code>pp</code> argument, which is an instance of the <a href="PP.html"><code>PP</code></a> class. The method uses <a href="PrettyPrint.html#method-i-text"><code>text</code></a>, <a href="PrettyPrint.html#method-i-breakable"><code>breakable</code></a>, <a href="PrettyPrint.html#method-i-nest"><code>nest</code></a>, <a href="PrettyPrint.html#method-i-group"><code>group</code></a> and <a href="PP/PPMethods.html#method-i-pp"><code>pp</code></a> to print the object.</p>
<h2 id="class-PP-label-Pretty-Print+JSON">Pretty-Print <a href="JSON.html"><code>JSON</code></a><span><a href="#class-PP-label-Pretty-Print+JSON">¶</a> <a href="#top">↑</a></span></h2>
<p>To pretty-print <a href="JSON.html"><code>JSON</code></a> refer to <a href="JSON.html#method-i-pretty_generate"><code>JSON#pretty_generate</code></a>.</p>
<h2 id="class-PP-label-Author">Author<span><a href="#class-PP-label-Author">¶</a> <a href="#top">↑</a></span></h2>
<p>Tanaka Akira <akr@fsij.org></p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section class="attribute-method-details" class="method-section">
<header>
<h3>Attributes</h3>
</header>
<div id="attribute-c-sharing_detection" class="method-detail">
<div class="method-heading attribute-method-heading">
<span class="method-name">sharing_detection</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>Returns the sharing detection flag as a boolean value. It is false by default.</p>
</div>
</div>
</section>
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-pp" class="method-detail ">
<div class="method-heading">
<span class="method-name">pp</span><span
class="method-args">(obj, out=$>, width=79)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Outputs <code>obj</code> to <code>out</code> in pretty printed format of <code>width</code> columns in width.</p>
<p>If <code>out</code> is omitted, <code>$></code> is assumed. If <code>width</code> is omitted, 79 is assumed.</p>
<p><a href="PP.html#method-c-pp"><code>PP.pp</code></a> returns <code>out</code>.</p>
<div class="method-source-code" id="pp-source">
<pre><span class="ruby-comment"># File lib/pp.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PP</span>.<span class="ruby-identifier ruby-title">pp</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">out</span>=<span class="ruby-identifier">$></span>, <span class="ruby-identifier">width</span>=<span class="ruby-value">79</span>)
<span class="ruby-identifier">q</span> = <span class="ruby-constant">PP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">out</span>, <span class="ruby-identifier">width</span>)
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">guard_inspect_key</span> {<span class="ruby-identifier">q</span>.<span class="ruby-identifier">pp</span> <span class="ruby-identifier">obj</span>}
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-comment">#$pp = q</span>
<span class="ruby-identifier">out</span> <span class="ruby-operator"><<</span> <span class="ruby-string">"\n"</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div id="method-c-singleline_pp" class="method-detail ">
<div class="method-heading">
<span class="method-name">singleline_pp</span><span
class="method-args">(obj, out=$>)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Outputs <code>obj</code> to <code>out</code> like <a href="PP.html#method-c-pp"><code>PP.pp</code></a> but with no indent and newline.</p>
<p><a href="PP.html#method-c-singleline_pp"><code>PP.singleline_pp</code></a> returns <code>out</code>.</p>
<div class="method-source-code" id="singleline_pp-source">
<pre><span class="ruby-comment"># File lib/pp.rb, line 83</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">PP</span>.<span class="ruby-identifier ruby-title">singleline_pp</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">out</span>=<span class="ruby-identifier">$></span>)
<span class="ruby-identifier">q</span> = <span class="ruby-constant">SingleLine</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">out</span>)
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">guard_inspect_key</span> {<span class="ruby-identifier">q</span>.<span class="ruby-identifier">pp</span> <span class="ruby-identifier">obj</span>}
<span class="ruby-identifier">q</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-identifier">out</span>
<span class="ruby-keyword">end</span></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>