twitter-status-bot/.gems/doc/json-1.8.1/rdoc/JSON/Pure/Generator/State.html

964 lines
39 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Class: JSON::Pure::Generator::State</title>
<link rel="stylesheet" href="../../../rdoc.css" type="text/css" media="screen" />
<script src="../../../js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/darkfish.js" type="text/javascript" charset="utf-8"></script>
</head>
<body id="top" class="class">
<div id="metadata">
<div id="home-metadata">
<div id="home-section" class="section">
<h3 class="section-header">
<a href="../../../index.html">Home</a>
<a href="../../../index.html#classes">Classes</a>
<a href="../../../index.html#methods">Methods</a>
</h3>
</div>
</div>
<div id="file-metadata">
<div id="file-list-section" class="section">
<h3 class="section-header">In Files</h3>
<div class="section-body">
<ul>
<li><a href="../../../lib/json/pure/generator_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
class="thickbox" title="lib/json/pure/generator.rb">lib/json/pure/generator.rb</a></li>
</ul>
</div>
</div>
</div>
<div id="class-metadata">
<!-- Parent Class -->
<div id="parent-class-section" class="section">
<h3 class="section-header">Parent</h3>
<p class="link">Object</p>
</div>
<!-- Method Quickref -->
<div id="method-list-section" class="section">
<h3 class="section-header">Methods</h3>
<ul class="link-list">
<li><a href="#method-c-from_state">::from_state</a></li>
<li><a href="#method-c-new">::new</a></li>
<li><a href="#method-i-5B-5D">#[]</a></li>
<li><a href="#method-i-5B-5D-3D">#[]=</a></li>
<li><a href="#method-i-allow_nan-3F">#allow_nan?</a></li>
<li><a href="#method-i-ascii_only-3F">#ascii_only?</a></li>
<li><a href="#method-i-check_circular-3F">#check_circular?</a></li>
<li><a href="#method-i-configure">#configure</a></li>
<li><a href="#method-i-generate">#generate</a></li>
<li><a href="#method-i-merge">#merge</a></li>
<li><a href="#method-i-quirks_mode-3F">#quirks_mode?</a></li>
<li><a href="#method-i-to_h">#to_h</a></li>
<li><a href="#method-i-to_hash">#to_hash</a></li>
</ul>
</div>
</div>
<div id="project-metadata">
<div id="fileindex-section" class="section project-section">
<h3 class="section-header">Files</h3>
<ul>
<li class="file"><a href="../../../README_rdoc.html">README.rdoc</a></li>
</ul>
</div>
<div id="classindex-section" class="section project-section">
<h3 class="section-header">Class/Module Index
<span class="search-toggle"><img src="../../../images/find.png"
height="16" width="16" alt="[+]"
title="show/hide quicksearch" /></span></h3>
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
<fieldset>
<legend>Quicksearch</legend>
<input type="text" name="quicksearch" value=""
class="quicksearch-field" />
</fieldset>
</form>
<ul class="link-list">
<li><a href="../../../JSON.html">JSON</a></li>
<li><a href="../../../JSON/Ext.html">JSON::Ext</a></li>
<li><a href="../../../JSON/GeneratorError.html">JSON::GeneratorError</a></li>
<li><a href="../../../JSON/GenericObject.html">JSON::GenericObject</a></li>
<li><a href="../../../JSON/JSONError.html">JSON::JSONError</a></li>
<li><a href="../../../JSON/MissingUnicodeSupport.html">JSON::MissingUnicodeSupport</a></li>
<li><a href="../../../JSON/NestingError.html">JSON::NestingError</a></li>
<li><a href="../../../JSON/ParserError.html">JSON::ParserError</a></li>
<li><a href="../../../JSON/Pure.html">JSON::Pure</a></li>
<li><a href="../../../JSON/Pure/Generator.html">JSON::Pure::Generator</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods.html">JSON::Pure::Generator::GeneratorMethods</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/Array.html">JSON::Pure::Generator::GeneratorMethods::Array</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/FalseClass.html">JSON::Pure::Generator::GeneratorMethods::FalseClass</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/Float.html">JSON::Pure::Generator::GeneratorMethods::Float</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/Hash.html">JSON::Pure::Generator::GeneratorMethods::Hash</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/Integer.html">JSON::Pure::Generator::GeneratorMethods::Integer</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/NilClass.html">JSON::Pure::Generator::GeneratorMethods::NilClass</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/Object.html">JSON::Pure::Generator::GeneratorMethods::Object</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/String.html">JSON::Pure::Generator::GeneratorMethods::String</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/String/Extend.html">JSON::Pure::Generator::GeneratorMethods::String::Extend</a></li>
<li><a href="../../../JSON/Pure/Generator/GeneratorMethods/TrueClass.html">JSON::Pure::Generator::GeneratorMethods::TrueClass</a></li>
<li><a href="../../../JSON/Pure/Generator/State.html">JSON::Pure::Generator::State</a></li>
<li><a href="../../../JSON/Pure/Parser.html">JSON::Pure::Parser</a></li>
<li><a href="../../../JSON/GeneratorError.html">JSON::UnparserError</a></li>
<li><a href="../../../BigDecimal.html">BigDecimal</a></li>
<li><a href="../../../Class.html">Class</a></li>
<li><a href="../../../Complex.html">Complex</a></li>
<li><a href="../../../Date.html">Date</a></li>
<li><a href="../../../DateTime.html">DateTime</a></li>
<li><a href="../../../Exception.html">Exception</a></li>
<li><a href="../../../Kernel.html">Kernel</a></li>
<li><a href="../../../OpenStruct.html">OpenStruct</a></li>
<li><a href="../../../Range.html">Range</a></li>
<li><a href="../../../Rational.html">Rational</a></li>
<li><a href="../../../Regexp.html">Regexp</a></li>
<li><a href="../../../Struct.html">Struct</a></li>
<li><a href="../../../Symbol.html">Symbol</a></li>
<li><a href="../../../Time.html">Time</a></li>
</ul>
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
</div>
</div>
</div>
<div id="documentation">
<h1 class="class">JSON::Pure::Generator::State</h1>
<div id="description" class="description">
<p>This class is used to create <a href="State.html">State</a> instances, that
are use to hold data while generating a <a
href="../../../JSON.html">JSON</a> text from a Ruby data structure.</p>
</div><!-- description -->
<div id="5Buntitled-5D" class="documentation-section">
<!-- Attributes -->
<div id="attribute-method-details" class="method-section section">
<h3 class="section-header">Attributes</h3>
<div id="array_nl-attribute-method" class="method-detail">
<a name="array_nl"></a>
<a name="array_nl="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">array_nl</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This string is put at the end of a line that holds a <a
href="../../../JSON.html">JSON</a> array.</p>
</div>
</div>
<div id="depth-attribute-method" class="method-detail">
<a name="depth"></a>
<a name="depth="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">depth</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This integer returns the current depth data structure nesting in the
generated <a href="../../../JSON.html">JSON</a>.</p>
</div>
</div>
<div id="indent-attribute-method" class="method-detail">
<a name="indent"></a>
<a name="indent="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">indent</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This string is used to indent levels in the <a
href="../../../JSON.html">JSON</a> text.</p>
</div>
</div>
<div id="max_nesting-attribute-method" class="method-detail">
<a name="max_nesting"></a>
<a name="max_nesting="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">max_nesting</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This integer returns the maximum level of data structure nesting in the
generated <a href="../../../JSON.html">JSON</a>, <a
href="State.html#attribute-i-max_nesting">max_nesting</a> = 0 if no maximum
is checked.</p>
</div>
</div>
<div id="object_nl-attribute-method" class="method-detail">
<a name="object_nl"></a>
<a name="object_nl="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">object_nl</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This string is put at the end of a line that holds a <a
href="../../../JSON.html">JSON</a> object (or Hash).</p>
</div>
</div>
<div id="quirks_mode-attribute-method" class="method-detail">
<a name="quirks_mode"></a>
<a name="quirks_mode="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">quirks_mode</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>If this attribute is set to true, quirks mode is enabled, otherwise its
disabled.</p>
</div>
</div>
<div id="space-attribute-method" class="method-detail">
<a name="space"></a>
<a name="space="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">space</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This string is used to insert a space between the tokens in a <a
href="../../../JSON.html">JSON</a> string.</p>
</div>
</div>
<div id="space_before-attribute-method" class="method-detail">
<a name="space_before"></a>
<a name="space_before="></a>
<div class="method-heading attribute-method-heading">
<span class="method-name">space_before</span><span
class="attribute-access-type">[RW]</span>
</div>
<div class="method-description">
<p>This string is used to insert a space before the : in <a
href="../../../JSON.html">JSON</a> objects.</p>
</div>
</div>
</div><!-- attribute-method-details -->
<!-- Methods -->
<div id="public-class-method-details" class="method-section section">
<h3 class="section-header">Public Class Methods</h3>
<div id="from_state-method" class="method-detail ">
<a name="method-c-from_state"></a>
<div class="method-heading">
<span class="method-name">from_state</span><span
class="method-args">(opts)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Creates a <a href="State.html">State</a> object from <em>opts</em>, which
ought to be Hash to create a new <a href="State.html">State</a> instance
configured by <em>opts</em>, something else to create an unconfigured
instance. If <em>opts</em> is a <a href="State.html">State</a> object, it
is just returned.</p>
<div class="method-source-code" id="from_state-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 129</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">from_state</span>(<span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">case</span>
<span class="ruby-keyword">when</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">opts</span>
<span class="ruby-identifier">opts</span>
<span class="ruby-keyword">when</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_hash</span>)
<span class="ruby-identifier">new</span>(<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">to_hash</span>)
<span class="ruby-keyword">when</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_h</span>)
<span class="ruby-identifier">new</span>(<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">to_h</span>)
<span class="ruby-keyword">else</span>
<span class="ruby-constant">SAFE_STATE_PROTOTYPE</span>.<span class="ruby-identifier">dup</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- from_state-source -->
</div>
</div><!-- from_state-method -->
<div id="new-method" class="method-detail ">
<a name="method-c-new"></a>
<div class="method-heading">
<span class="method-name">new</span><span
class="method-args">(opts = {})</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Instantiates a new <a href="State.html">State</a> object, configured by
<em>opts</em>.</p>
<p><em>opts</em> can have the following keys:</p>
<ul><li>
<p><b>indent</b>: a string used to indent levels (default: "),</p>
</li><li>
<p><b>space</b>: a string that is put after, a : or , delimiter (default: "),</p>
</li><li>
<p><b><a href="State.html#attribute-i-space_before">space_before</a></b>: a
string that is put before a : pair delimiter (default: "),</p>
</li><li>
<p><b><a href="State.html#attribute-i-object_nl">object_nl</a></b>: a string
that is put at the end of a <a href="../../../JSON.html">JSON</a> object
(default: "),</p>
</li><li>
<p><b><a href="State.html#attribute-i-array_nl">array_nl</a></b>: a string
that is put at the end of a <a href="../../../JSON.html">JSON</a> array
(default: "),</p>
</li><li>
<p><b>check_circular</b>: is deprecated now, use the :<a
href="State.html#attribute-i-max_nesting">max_nesting</a> option instead,</p>
</li><li>
<p><b><a href="State.html#attribute-i-max_nesting">max_nesting</a></b>: sets
the maximum level of data structure nesting in the generated <a
href="../../../JSON.html">JSON</a>, <a
href="State.html#attribute-i-max_nesting">max_nesting</a> = 0 if no maximum
should be checked.</p>
</li><li>
<p><b>allow_nan</b>: true if NaN, Infinity, and -Infinity should be generated,
otherwise an exception is thrown, if these values are encountered. This
options defaults to false.</p>
</li><li>
<p><b><a href="State.html#attribute-i-quirks_mode">quirks_mode</a></b>:
Enables <a href="State.html#attribute-i-quirks_mode">quirks_mode</a> for
parser, that is for example generating single <a
href="../../../JSON.html">JSON</a> values instead of documents is possible.</p>
</li></ul>
<div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 159</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">opts</span> = {})
<span class="ruby-ivar">@indent</span> = <span class="ruby-string">''</span>
<span class="ruby-ivar">@space</span> = <span class="ruby-string">''</span>
<span class="ruby-ivar">@space_before</span> = <span class="ruby-string">''</span>
<span class="ruby-ivar">@object_nl</span> = <span class="ruby-string">''</span>
<span class="ruby-ivar">@array_nl</span> = <span class="ruby-string">''</span>
<span class="ruby-ivar">@allow_nan</span> = <span class="ruby-keyword">false</span>
<span class="ruby-ivar">@ascii_only</span> = <span class="ruby-keyword">false</span>
<span class="ruby-ivar">@quirks_mode</span> = <span class="ruby-keyword">false</span>
<span class="ruby-ivar">@buffer_initial_length</span> = <span class="ruby-value">1024</span>
<span class="ruby-identifier">configure</span> <span class="ruby-identifier">opts</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- new-source -->
</div>
</div><!-- new-method -->
</div><!-- public-class-method-details -->
<div id="public-instance-method-details" class="method-section section">
<h3 class="section-header">Public Instance Methods</h3>
<div id="5B-5D-method" class="method-detail ">
<a name="method-i-5B-5D"></a>
<div class="method-heading">
<span class="method-name">[]</span><span
class="method-args">(name)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Return the value returned by method <tt>name</tt>.</p>
<div class="method-source-code" id="5B-5D-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 307</span>
<span class="ruby-keyword">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-identifier">name</span>)
<span class="ruby-keyword">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">name</span>)
<span class="ruby-identifier">__send__</span>(<span class="ruby-identifier">name</span>)
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">&quot;@#{name}&quot;</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- 5B-5D-source -->
</div>
</div><!-- 5B-5D-method -->
<div id="5B-5D-3D-method" class="method-detail ">
<a name="method-i-5B-5D-3D"></a>
<div class="method-heading">
<span class="method-name">[]=</span><span
class="method-args">(name, value)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<div class="method-source-code" id="5B-5D-3D-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 315</span>
<span class="ruby-keyword">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
<span class="ruby-keyword">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">name_writer</span> = <span class="ruby-node">&quot;#{name}=&quot;</span>)
<span class="ruby-identifier">__send__</span> <span class="ruby-identifier">name_writer</span>, <span class="ruby-identifier">value</span>
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">instance_variable_set</span> <span class="ruby-node">&quot;@#{name}&quot;</span>, <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- 5B-5D-3D-source -->
</div>
</div><!-- 5B-5D-3D-method -->
<div id="allow_nan-3F-method" class="method-detail ">
<a name="method-i-allow_nan-3F"></a>
<div class="method-heading">
<span class="method-name">allow_nan?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if NaN, Infinity, and -Infinity should be considered as valid
<a href="../../../JSON.html">JSON</a> and output.</p>
<div class="method-source-code" id="allow_nan-3F-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 226</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">allow_nan?</span>
<span class="ruby-ivar">@allow_nan</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- allow_nan-3F-source -->
</div>
</div><!-- allow_nan-3F-method -->
<div id="ascii_only-3F-method" class="method-detail ">
<a name="method-i-ascii_only-3F"></a>
<div class="method-heading">
<span class="method-name">ascii_only?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true, if only ASCII characters should be generated. Otherwise
returns false.</p>
<div class="method-source-code" id="ascii_only-3F-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 232</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">ascii_only?</span>
<span class="ruby-ivar">@ascii_only</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- ascii_only-3F-source -->
</div>
</div><!-- ascii_only-3F-method -->
<div id="check_circular-3F-method" class="method-detail ">
<a name="method-i-check_circular-3F"></a>
<div class="method-heading">
<span class="method-name">check_circular?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true, if circular data structures are checked, otherwise returns
false.</p>
<div class="method-source-code" id="check_circular-3F-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 220</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">check_circular?</span>
<span class="ruby-operator">!</span><span class="ruby-ivar">@max_nesting</span>.<span class="ruby-identifier">zero?</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- check_circular-3F-source -->
</div>
</div><!-- check_circular-3F-method -->
<div id="configure-method" class="method-detail ">
<a name="method-i-configure"></a>
<div class="method-heading">
<span class="method-name">configure</span><span
class="method-args">(opts)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Configure this <a href="State.html">State</a> instance with the Hash
<em>opts</em>, and return itself.</p>
<div class="method-source-code" id="configure-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 243</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">configure</span>(<span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_hash</span>)
<span class="ruby-identifier">opts</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">to_hash</span>
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_h</span>)
<span class="ruby-identifier">opts</span> = <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">to_h</span>
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;can't convert #{opts.class} into Hash&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">for</span> <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">opts</span>
<span class="ruby-identifier">instance_variable_set</span> <span class="ruby-node">&quot;@#{key}&quot;</span>, <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span>
<span class="ruby-ivar">@indent</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:indent</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:indent</span>)
<span class="ruby-ivar">@space</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:space</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:space</span>)
<span class="ruby-ivar">@space_before</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:space_before</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:space_before</span>)
<span class="ruby-ivar">@object_nl</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:object_nl</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:object_nl</span>)
<span class="ruby-ivar">@array_nl</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:array_nl</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:array_nl</span>)
<span class="ruby-ivar">@allow_nan</span> = <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">opts</span>[<span class="ruby-value">:allow_nan</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:allow_nan</span>)
<span class="ruby-ivar">@ascii_only</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:ascii_only</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:ascii_only</span>)
<span class="ruby-ivar">@depth</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:depth</span>] <span class="ruby-operator">||</span> <span class="ruby-value">0</span>
<span class="ruby-ivar">@quirks_mode</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:quirks_mode</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:quirks_mode</span>)
<span class="ruby-ivar">@buffer_initial_length</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:buffer_initial_length</span>]
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">opts</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:max_nesting</span>) <span class="ruby-comment"># defaults to 100</span>
<span class="ruby-ivar">@max_nesting</span> = <span class="ruby-value">100</span>
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:max_nesting</span>]
<span class="ruby-ivar">@max_nesting</span> = <span class="ruby-identifier">opts</span>[<span class="ruby-value">:max_nesting</span>]
<span class="ruby-keyword">else</span>
<span class="ruby-ivar">@max_nesting</span> = <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- configure-source -->
</div>
<div class="aliases">
Also aliased as: <a href="State.html#method-i-merge">merge</a>
</div>
</div><!-- configure-method -->
<div id="generate-method" class="method-detail ">
<a name="method-i-generate"></a>
<div class="method-heading">
<span class="method-name">generate</span><span
class="method-args">(obj)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Generates a valid <a href="../../../JSON.html">JSON</a> document from
object <tt>obj</tt> and returns the result. If no valid <a
href="../../../JSON.html">JSON</a> document can be created this method
raises a <a href="../../GeneratorError.html">GeneratorError</a> exception.</p>
<div class="method-source-code" id="generate-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 292</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">generate</span>(<span class="ruby-identifier">obj</span>)
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">to_json</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-constant">JSON</span>.<span class="ruby-identifier">valid_utf8?</span>(<span class="ruby-identifier">result</span>) <span class="ruby-keyword">or</span> <span class="ruby-identifier">raise</span> <span class="ruby-constant">GeneratorError</span>,
<span class="ruby-node">&quot;source sequence #{result.inspect} is illegal/malformed utf-8&quot;</span>
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@quirks_mode</span>
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\A\s*\[/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\]\s*\Z/</span> <span class="ruby-operator">||</span>
<span class="ruby-identifier">result</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\A\s*\{/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">result</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\}\s*\Z/</span>
<span class="ruby-keyword">then</span>
<span class="ruby-identifier">raise</span> <span class="ruby-constant">GeneratorError</span>, <span class="ruby-string">&quot;only generation of JSON objects or arrays allowed&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- generate-source -->
</div>
</div><!-- generate-method -->
<div id="merge-method" class="method-detail method-alias">
<a name="method-i-merge"></a>
<div class="method-heading">
<span class="method-name">merge</span><span
class="method-args">(opts)</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
</div>
<div class="aliases">
Alias for: <a href="State.html#method-i-configure">configure</a>
</div>
</div><!-- merge-method -->
<div id="quirks_mode-3F-method" class="method-detail ">
<a name="method-i-quirks_mode-3F"></a>
<div class="method-heading">
<span class="method-name">quirks_mode?</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true, if quirks mode is enabled. Otherwise returns false.</p>
<div class="method-source-code" id="quirks_mode-3F-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 237</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">quirks_mode?</span>
<span class="ruby-ivar">@quirks_mode</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- quirks_mode-3F-source -->
</div>
</div><!-- quirks_mode-3F-method -->
<div id="to_h-method" class="method-detail ">
<a name="method-i-to_h"></a>
<div class="method-heading">
<span class="method-name">to_h</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the configuration instance variables as a hash, that can be passed
to the configure method.</p>
<div class="method-source-code" id="to_h-source">
<pre>
<span class="ruby-comment"># File lib/json/pure/generator.rb, line 278</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_h</span>
<span class="ruby-identifier">result</span> = {}
<span class="ruby-keyword">for</span> <span class="ruby-identifier">iv</span> <span class="ruby-keyword">in</span> <span class="ruby-identifier">instance_variables</span>
<span class="ruby-identifier">iv</span> = <span class="ruby-identifier">iv</span>.<span class="ruby-identifier">to_s</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
<span class="ruby-identifier">result</span>[<span class="ruby-identifier">iv</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-keyword">self</span>[<span class="ruby-identifier">iv</span>]
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">result</span>
<span class="ruby-keyword">end</span></pre>
</div><!-- to_h-source -->
</div>
<div class="aliases">
Also aliased as: <a href="State.html#method-i-to_hash">to_hash</a>
</div>
</div><!-- to_h-method -->
<div id="to_hash-method" class="method-detail method-alias">
<a name="method-i-to_hash"></a>
<div class="method-heading">
<span class="method-name">to_hash</span><span
class="method-args">()</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
</div>
<div class="aliases">
Alias for: <a href="State.html#method-i-to_h">to_h</a>
</div>
</div><!-- to_hash-method -->
</div><!-- public-instance-method-details -->
</div><!-- 5Buntitled-5D -->
</div><!-- documentation -->
<div id="validator-badges">
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
Rdoc Generator</a> 2</small>.</p>
</div>
</body>
</html>