diff options
Diffstat (limited to 'doc/classes/JSON.html')
-rw-r--r-- | doc/classes/JSON.html | 1142 |
1 files changed, 0 insertions, 1142 deletions
diff --git a/doc/classes/JSON.html b/doc/classes/JSON.html deleted file mode 100644 index 3b5fb26..0000000 --- a/doc/classes/JSON.html +++ /dev/null @@ -1,1142 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head> - <title>JSON</title> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" /> -<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" /> -<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" /> -<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script> -<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script> -<script src="../js/main.js" type="text/javascript" charset="utf-8"></script> -<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script> - -</head> - -<body> - <div class="banner"> - - <h1> - <span class="type">Module</span> - JSON - - </h1> - <ul class="files"> - - <li><a href="../files/lib/json_rb.html">lib/json.rb</a></li> - - <li><a href="../files/lib/json/version_rb.html">lib/json/version.rb</a></li> - - <li><a href="../files/lib/json/common_rb.html">lib/json/common.rb</a></li> - - <li><a href="../files/lib/json/pure/generator_rb.html">lib/json/pure/generator.rb</a></li> - - <li><a href="../files/lib/json/pure/parser_rb.html">lib/json/pure/parser.rb</a></li> - - <li><a href="../files/lib/json/ext_rb.html">lib/json/ext.rb</a></li> - - <li><a href="../files/lib/json/pure_rb.html">lib/json/pure.rb</a></li> - - <li><a href="../files/ext/json/ext/parser/parser_c.html">ext/json/ext/parser/parser.c</a></li> - - <li><a href="../files/ext/json/ext/generator/generator_c.html">ext/json/ext/generator/generator.c</a></li> - - </ul> - </div> - <div id="bodyContent"> - <div id="content"> - - - - - - - - - - - - <!-- Namespace --> - <div class="sectiontitle">Namespace</div> - <ul> - - <li> - <span class="type">MODULE</span> - <a href="JSON/Ext.html">JSON::Ext</a> - </li> - - <li> - <span class="type">MODULE</span> - <a href="JSON/Pure.html">JSON::Pure</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/CircularDatastructure.html">JSON::CircularDatastructure</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/GeneratorError.html">JSON::GeneratorError</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/JSONError.html">JSON::JSONError</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/MissingUnicodeSupport.html">JSON::MissingUnicodeSupport</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/NestingError.html">JSON::NestingError</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/ParserError.html">JSON::ParserError</a> - </li> - - <li> - <span class="type">CLASS</span> - <a href="JSON/GeneratorError.html">JSON::UnparserError</a> - </li> - - </ul> - - - - - <!-- Method ref --> - <div class="sectiontitle">Methods</div> - <dl class="methods"> - - <dt>#</dt> - <dd> - <ul> - - - <li> - <a href="#method-c-5B-5D">[]</a> - </li> - - </ul> - </dd> - - <dt>C</dt> - <dd> - <ul> - - - <li> - <a href="#method-c-const_defined_in-3F">const_defined_in?</a> - </li> - - </ul> - </dd> - - <dt>D</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-dump">dump</a> - </li> - - </ul> - </dd> - - <dt>F</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-fast_generate">fast_generate</a> - </li> - - </ul> - </dd> - - <dt>G</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-generate">generate</a> - </li> - - </ul> - </dd> - - <dt>I</dt> - <dd> - <ul> - - - <li> - <a href="#method-c-iconv">iconv</a> - </li> - - </ul> - </dd> - - <dt>L</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-load">load</a> - </li> - - </ul> - </dd> - - <dt>P</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-parse">parse</a>, - </li> - - - <li> - <a href="#method-i-parse-21">parse!</a>, - </li> - - - <li> - <a href="#method-i-pretty_generate">pretty_generate</a> - </li> - - </ul> - </dd> - - <dt>R</dt> - <dd> - <ul> - - - <li> - <a href="#method-i-recurse_proc">recurse_proc</a>, - </li> - - - <li> - <a href="#method-c-restore">restore</a> - </li> - - </ul> - </dd> - - </dl> - - - - - - - - - - - - - - <!-- Section constants --> - <div class="sectiontitle">Constants</div> - <table border='0' cellpadding='5'> - - <tr valign='top'> - <td class="attr-name">VERSION</td> - <td>=</td> - <td class="attr-value">'1.6.4'</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"><p><a href="JSON.html">JSON</a> version</p></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">VERSION_ARRAY</td> - <td>=</td> - <td class="attr-value">VERSION.split(/\./).map { |x| x.to_i }</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">VERSION_MAJOR</td> - <td>=</td> - <td class="attr-value">VERSION_ARRAY[0]</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">VERSION_MINOR</td> - <td>=</td> - <td class="attr-value">VERSION_ARRAY[1]</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">VERSION_BUILD</td> - <td>=</td> - <td class="attr-value">VERSION_ARRAY[2]</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">NaN</td> - <td>=</td> - <td class="attr-value">0.0/0</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">Infinity</td> - <td>=</td> - <td class="attr-value">1.0/0</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">MinusInfinity</td> - <td>=</td> - <td class="attr-value">-Infinity</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">UnparserError</td> - <td>=</td> - <td class="attr-value">GeneratorError</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"><p>For backwards compatibility</p></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">MAP</td> - <td>=</td> - <td class="attr-value">{ -"\x0" => '\u0000', -"\x1" => '\u0001', -"\x2" => '\u0002', -"\x3" => '\u0003', -"\x4" => '\u0004', -"\x5" => '\u0005', -"\x6" => '\u0006', -"\x7" => '\u0007', -"\b" => '\b', -"\t" => '\t', -"\n" => '\n', -"\xb" => '\u000b', -"\f" => '\f', -"\r" => '\r', -"\xe" => '\u000e', -"\xf" => '\u000f', -"\x10" => '\u0010', -"\x11" => '\u0011', -"\x12" => '\u0012', -"\x13" => '\u0013', -"\x14" => '\u0014', -"\x15" => '\u0015', -"\x16" => '\u0016', -"\x17" => '\u0017', -"\x18" => '\u0018', -"\x19" => '\u0019', -"\x1a" => '\u001a', -"\x1b" => '\u001b', -"\x1c" => '\u001c', -"\x1d" => '\u001d', -"\x1e" => '\u001e', -"\x1f" => '\u001f', -'"' => '\"', -'\\' => '\\\\', -}</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - <tr valign='top'> - <td class="attr-name">JSON_LOADED</td> - <td>=</td> - <td class="attr-value">true unless defined?(::JSON::JSON_LOADED)</td> - </tr> - - <tr valign='top'> - <td> </td> - <td colspan="2" class="attr-desc"></td> - </tr> - - - </table> - - - - - <!-- Section attributes --> - <div class="sectiontitle">Attributes</div> - <table border='0' cellpadding='5'> - - <tr valign='top'> - <td class='attr-rw'> - [RW] - </td> - <td class='attr-name'>create_id</td> - <td class='attr-desc'><p>This is create identifier, which is used to decide if the -<em>json_create</em> hook of a class should be called. It defaults to -‘json_class’.</p></td> - </tr> - - <tr valign='top'> - <td class='attr-rw'> - [RW] - </td> - <td class='attr-name'>dump_default_options</td> - <td class='attr-desc'><p>The global default options for the <a -href="JSON.html#method-i-dump">#dump</a> method:</p> - -<pre>:max_nesting: false -:allow_nan: true -:quirks_mode: true</pre></td> - </tr> - - <tr valign='top'> - <td class='attr-rw'> - [R] - </td> - <td class='attr-name'>generator</td> - <td class='attr-desc'><p>Returns the <a href="JSON.html">JSON</a> generator module that is used by -<a href="JSON.html">JSON</a>. This is either <a -href="JSON/Ext/Generator.html">JSON::Ext::Generator</a> or <a -href="JSON/Pure/Generator.html">JSON::Pure::Generator</a>.</p></td> - </tr> - - <tr valign='top'> - <td class='attr-rw'> - [RW] - </td> - <td class='attr-name'>load_default_options</td> - <td class='attr-desc'><p>The global default options for the <a -href="JSON.html#method-i-load">#load</a> method:</p> - -<pre>:max_nesting: false -:allow_nan: true -:quirks_mode: true</pre></td> - </tr> - - <tr valign='top'> - <td class='attr-rw'> - [R] - </td> - <td class='attr-name'>parser</td> - <td class='attr-desc'><p>Returns the <a href="JSON.html">JSON</a> parser class that is used by <a -href="JSON.html">JSON</a>. This is either <a -href="JSON/Ext/Parser.html">JSON::Ext::Parser</a> or <a -href="JSON/Pure/Parser.html">JSON::Pure::Parser</a>.</p></td> - </tr> - - <tr valign='top'> - <td class='attr-rw'> - [RW] - </td> - <td class='attr-name'>state</td> - <td class='attr-desc'><p>Returns the <a href="JSON.html">JSON</a> generator state class that is used -by <a href="JSON.html">JSON</a>. This is either <a -href="JSON/Ext/Generator/State.html">JSON::Ext::Generator::State</a> or <a -href="JSON/Pure/Generator/State.html">JSON::Pure::Generator::State</a>.</p></td> - </tr> - - </table> - - - - <!-- Methods --> - - <div class="sectiontitle">Class Public methods</div> - - <div class="method"> - <div class="title method-title" id="method-c-5B-5D"> - - <a name="method-c-5B-5D"></a><b>[]</b>(object, opts = {}) - - </div> - - - <div class="description"> - <p>If <em>object</em> is string-like, parse the string and return the parsed -result as a Ruby data structure. Otherwise generate a <a -href="JSON.html">JSON</a> text from the Ruby data structure object and -return it.</p> - -<p>The <em>opts</em> argument is passed through to generate/parse -respectively. See generate and parse for their documentation.</p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-c-5B-5D_source')" id="l_method-c-5B-5D_source">show</a> - - </p> - <div id="method-c-5B-5D_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 11</span> -<span class="ruby-keyword">def</span> <span class="ruby-operator">[]</span>(<span class="ruby-keyword ruby-title">object</span>, <span class="ruby-identifier">opts</span> = {}) - <span class="ruby-keyword">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:to_str</span> - <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">object</span>.<span class="ruby-identifier">to_str</span>, <span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">else</span> - <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-c-const_defined_in-3F"> - - <a name="method-c-const_defined_in-3F"></a><b>const_defined_in?</b>(modul, constant) - - </div> - - - <div class="description"> - - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-c-const_defined_in-3F_source')" id="l_method-c-const_defined_in-3F_source">show</a> - - </p> - <div id="method-c-const_defined_in-3F_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 415</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">const_defined_in?</span>(<span class="ruby-identifier">modul</span>, <span class="ruby-identifier">constant</span>) - <span class="ruby-identifier">modul</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-identifier">constant</span>) -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-c-iconv"> - - <a name="method-c-iconv"></a><b>iconv</b>(to, from, string) - - </div> - - - <div class="description"> - <p>Encodes string using Ruby’s <em>String.encode</em></p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-c-iconv_source')" id="l_method-c-iconv_source">show</a> - - </p> - <div id="method-c-iconv_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 403</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">iconv</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">from</span>, <span class="ruby-identifier">string</span>) - <span class="ruby-identifier">string</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-identifier">to</span>, <span class="ruby-identifier">from</span>) -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-c-restore"> - - <a name="method-c-restore"></a><b>restore</b>(source, proc = nil) - - </div> - - - <div class="description"> - - </div> - - - - - - </div> - - <div class="sectiontitle">Instance Public methods</div> - - <div class="method"> - <div class="title method-title" id="method-i-dump"> - - <a name="method-i-dump"></a><b>dump</b>(obj, anIO = nil, limit = nil) - - </div> - - - <div class="description"> - <p>Dumps <em>obj</em> as a <a href="JSON.html">JSON</a> string, i.e. calls -generate on the object and returns the result.</p> - -<p>If anIO (an IO-like object or an object that responds to the write method) -was given, the resulting <a href="JSON.html">JSON</a> is written to it.</p> - -<p>If the number of nested arrays or objects exceeds <em>limit</em>, an -ArgumentError exception is raised. This argument is similar (but not -exactly the same!) to the <em>limit</em> argument in Marshal.dump.</p> - -<p>The default options for the generator can be changed via the <a -href="JSON.html#attribute-c-dump_default_options">::dump_default_options</a> -method.</p> - -<p>This method is part of the implementation of the load/dump interface of -Marshal and YAML.</p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-dump_source')" id="l_method-i-dump_source">show</a> - - </p> - <div id="method-i-dump_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 370</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">dump</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">anIO</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">limit</span> = <span class="ruby-keyword">nil</span>) - <span class="ruby-keyword">if</span> <span class="ruby-identifier">anIO</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">limit</span>.<span class="ruby-identifier">nil?</span> - <span class="ruby-identifier">anIO</span> = <span class="ruby-identifier">anIO</span>.<span class="ruby-identifier">to_io</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">anIO</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_io</span>) - <span class="ruby-keyword">unless</span> <span class="ruby-identifier">anIO</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:write</span>) - <span class="ruby-identifier">limit</span> = <span class="ruby-identifier">anIO</span> - <span class="ruby-identifier">anIO</span> = <span class="ruby-keyword">nil</span> - <span class="ruby-keyword">end</span> - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">opts</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">dump_default_options</span> - <span class="ruby-identifier">limit</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">update</span>(<span class="ruby-value">:max_nesting</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">limit</span>) - <span class="ruby-identifier">result</span> = <span class="ruby-identifier">generate</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">if</span> <span class="ruby-identifier">anIO</span> - <span class="ruby-identifier">anIO</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">result</span> - <span class="ruby-identifier">anIO</span> - <span class="ruby-keyword">else</span> - <span class="ruby-identifier">result</span> - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">rescue</span> <span class="ruby-constant">JSON</span><span class="ruby-operator">::</span><span class="ruby-constant">NestingError</span> - <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">"exceed depth limit"</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-fast_generate"> - - <a name="method-i-fast_generate"></a><b>fast_generate</b>(obj, opts = nil) - - </div> - - - <div class="description"> - <p>Generate a <a href="JSON.html">JSON</a> document from the Ruby data -structure <em>obj</em> and return it. This method disables the checks for -circles in Ruby objects.</p> - -<p><strong>WARNING</strong>: Be careful not to pass any Ruby data structures -with circles as <em>obj</em> argument because this will cause <a -href="JSON.html">JSON</a> to go into an infinite loop.</p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-fast_generate_source')" id="l_method-i-fast_generate_source">show</a> - - </p> - <div id="method-i-fast_generate_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 231</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">fast_generate</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-keyword">nil</span>) - <span class="ruby-keyword">if</span> <span class="ruby-constant">State</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">opts</span> - <span class="ruby-identifier">state</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">opts</span>, <span class="ruby-keyword">nil</span> - <span class="ruby-keyword">else</span> - <span class="ruby-identifier">state</span> = <span class="ruby-constant">FAST_STATE_PROTOTYPE</span>.<span class="ruby-identifier">dup</span> - <span class="ruby-keyword">end</span> - <span class="ruby-keyword">if</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">"can't convert #{opts.class} into Hash"</span> - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span>.<span class="ruby-identifier">configure</span>(<span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">obj</span>) -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-generate"> - - <a name="method-i-generate"></a><b>generate</b>(obj, opts = nil) - - </div> - - - <div class="description"> - <p>Generate a <a href="JSON.html">JSON</a> document from the Ruby data -structure <em>obj</em> and return it. <em>state</em> is * a JSON::State -object,</p> -<ul><li> -<p>or a Hash like object (responding to to_hash),</p> -</li><li> -<p>an object convertible into a hash by a to_h method,</p> -</li></ul> - -<p>that is used as or to configure a State object.</p> - -<p>It defaults to a state object, that creates the shortest possible <a -href="JSON.html">JSON</a> text in one line, checks for circular data -structures and doesn’t allow <a href="JSON.html#NaN">NaN</a>, <a -href="JSON.html#Infinity">Infinity</a>, and -<a -href="JSON.html#Infinity">Infinity</a>.</p> - -<p>A <em>state</em> hash can have the following keys:</p> -<ul><li> -<p><strong>indent</strong>: a string used to indent levels (default: ”),</p> -</li><li> -<p><strong>space</strong>: a string that is put after, a : or , delimiter -(default: ”),</p> -</li><li> -<p><strong>space_before</strong>: a string that is put before a : pair -delimiter (default: ”),</p> -</li><li> -<p><strong>object_nl</strong>: a string that is put at the end of a <a -href="JSON.html">JSON</a> object (default: ”),</p> -</li><li> -<p><strong>array_nl</strong>: a string that is put at the end of a <a -href="JSON.html">JSON</a> array (default: ”),</p> -</li><li> -<p><strong>allow_nan</strong>: true if <a href="JSON.html#NaN">NaN</a>, <a -href="JSON.html#Infinity">Infinity</a>, and -<a -href="JSON.html#Infinity">Infinity</a> should be generated, otherwise an -exception is thrown if these values are encountered. This options defaults -to false.</p> -</li><li> -<p><strong>max_nesting</strong>: The maximum depth of nesting allowed in the -data structures from which <a href="JSON.html">JSON</a> is to be generated. -Disable depth checking with :max_nesting => false, it defaults to 19.</p> -</li></ul> - -<p>See also the <a href="JSON.html#method-i-fast_generate">#fast_generate</a> -for the fastest creation method with the least amount of sanity checks, and -the <a href="JSON.html#method-i-pretty_generate">#pretty_generate</a> -method for some defaults for pretty output.</p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-generate_source')" id="l_method-i-generate_source">show</a> - - </p> - <div id="method-i-generate_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 200</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">generate</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-keyword">nil</span>) - <span class="ruby-keyword">if</span> <span class="ruby-constant">State</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">opts</span> - <span class="ruby-identifier">state</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">opts</span>, <span class="ruby-keyword">nil</span> - <span class="ruby-keyword">else</span> - <span class="ruby-identifier">state</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">if</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">"can't convert #{opts.class} into Hash"</span> - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span> = <span class="ruby-identifier">state</span>.<span class="ruby-identifier">configure</span>(<span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">obj</span>) -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-load"> - - <a name="method-i-load"></a><b>load</b>(source, proc = nil) - - </div> - - - <div class="description"> - <p>Load a ruby data structure from a <a href="JSON.html">JSON</a> -<em>source</em> and return it. A source can either be a string-like object, -an IO-like object, or an object responding to the read method. If -<em>proc</em> was given, it will be called with any nested Ruby object as -an argument recursively in depth first order. The default options for the -parser can be changed via the <a -href="JSON.html#attribute-c-load_default_options">::load_default_options</a> -method.</p> - -<p>This method is part of the implementation of the load/dump interface of -Marshal and YAML.</p> - </div> - - - - <div class="aka"> - Also aliased as: <a href="JSON.html#method-i-restore">restore</a> - </div> - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-load_source')" id="l_method-i-load_source">show</a> - - </p> - <div id="method-i-load_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 308</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">load</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">proc</span> = <span class="ruby-keyword">nil</span>) - <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">load_default_options</span> - <span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:to_str</span> - <span class="ruby-identifier">source</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">to_str</span> - <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:to_io</span> - <span class="ruby-identifier">source</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">to_io</span>.<span class="ruby-identifier">read</span> - <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:read</span>) - <span class="ruby-identifier">source</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">read</span> - <span class="ruby-keyword">end</span> - <span class="ruby-keyword">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-value">:quirks_mode</span>] <span class="ruby-operator">&&</span> (<span class="ruby-identifier">source</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">empty?</span>) - <span class="ruby-identifier">source</span> = <span class="ruby-string">'null'</span> - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">result</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">opts</span>) - <span class="ruby-identifier">recurse_proc</span>(<span class="ruby-identifier">result</span>, &<span class="ruby-identifier">proc</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">proc</span> - <span class="ruby-identifier">result</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-parse"> - - <a name="method-i-parse"></a><b>parse</b>(source, opts = {}) - - </div> - - - <div class="description"> - <p>Parse the <a href="JSON.html">JSON</a> document <em>source</em> into a Ruby -data structure and return it.</p> - -<p><em>opts</em> can have the following keys:</p> -<ul><li> -<p><strong>max_nesting</strong>: The maximum depth of nesting allowed in the -parsed data structures. Disable depth checking with :max_nesting => -false. It defaults to 19.</p> -</li><li> -<p><strong>allow_nan</strong>: If set to true, allow <a -href="JSON.html#NaN">NaN</a>, <a href="JSON.html#Infinity">Infinity</a> and --<a href="JSON.html#Infinity">Infinity</a> in defiance of RFC 4627 to be -parsed by the Parser. This option defaults to false.</p> -</li><li> -<p><strong>symbolize_names</strong>: If set to true, returns symbols for the -names (keys) in a <a href="JSON.html">JSON</a> object. Otherwise strings -are returned. Strings are the default.</p> -</li><li> -<p><strong>create_additions</strong>: If set to false, the Parser doesn’t -create additions even if a matching class and <a -href="JSON.html#attribute-c-create_id">::create_id</a> was found. This -option defaults to true.</p> -</li><li> -<p><strong>object_class</strong>: Defaults to Hash</p> -</li><li> -<p><strong>array_class</strong>: Defaults to Array</p> -</li></ul> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-parse_source')" id="l_method-i-parse_source">show</a> - - </p> - <div id="method-i-parse_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 147</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">parse</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">opts</span> = {}) - <span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">opts</span>).<span class="ruby-identifier">parse</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-parse-21"> - - <a name="method-i-parse-21"></a><b>parse!</b>(source, opts = {}) - - </div> - - - <div class="description"> - <p>Parse the <a href="JSON.html">JSON</a> document <em>source</em> into a Ruby -data structure and return it. The bang version of the parse method defaults -to the more dangerous values for the <em>opts</em> hash, so be sure only to -parse trusted <em>source</em> documents.</p> - -<p><em>opts</em> can have the following keys:</p> -<ul><li> -<p><strong>max_nesting</strong>: The maximum depth of nesting allowed in the -parsed data structures. Enable depth checking with :max_nesting => -anInteger. The parse! methods defaults to not doing max depth checking: -This can be dangerous if someone wants to fill up your stack.</p> -</li><li> -<p><strong>allow_nan</strong>: If set to true, allow <a -href="JSON.html#NaN">NaN</a>, <a href="JSON.html#Infinity">Infinity</a>, -and -<a href="JSON.html#Infinity">Infinity</a> in defiance of RFC 4627 to -be parsed by the Parser. This option defaults to true.</p> -</li><li> -<p><strong>create_additions</strong>: If set to false, the Parser doesn’t -create additions even if a matching class and <a -href="JSON.html#attribute-c-create_id">::create_id</a> was found. This -option defaults to true.</p> -</li></ul> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-parse-21_source')" id="l_method-i-parse-21_source">show</a> - - </p> - <div id="method-i-parse-21_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 166</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">parse!</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">opts</span> = {}) - <span class="ruby-identifier">opts</span> = { - <span class="ruby-value">:max_nesting</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">false</span>, - <span class="ruby-value">:allow_nan</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span> - }.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">opts</span>) - <span class="ruby-constant">Parser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">source</span>, <span class="ruby-identifier">opts</span>).<span class="ruby-identifier">parse</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-pretty_generate"> - - <a name="method-i-pretty_generate"></a><b>pretty_generate</b>(obj, opts = nil) - - </div> - - - <div class="description"> - <p>Generate a <a href="JSON.html">JSON</a> document from the Ruby data -structure <em>obj</em> and return it. The returned document is a prettier -form of the document returned by unparse.</p> - -<p>The <em>opts</em> argument can be used to configure the generator. See the -generate method for a more detailed explanation.</p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-pretty_generate_source')" id="l_method-i-pretty_generate_source">show</a> - - </p> - <div id="method-i-pretty_generate_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 262</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">pretty_generate</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-keyword">nil</span>) - <span class="ruby-keyword">if</span> <span class="ruby-constant">State</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">opts</span> - <span class="ruby-identifier">state</span>, <span class="ruby-identifier">opts</span> = <span class="ruby-identifier">opts</span>, <span class="ruby-keyword">nil</span> - <span class="ruby-keyword">else</span> - <span class="ruby-identifier">state</span> = <span class="ruby-constant">PRETTY_STATE_PROTOTYPE</span>.<span class="ruby-identifier">dup</span> - <span class="ruby-keyword">end</span> - <span class="ruby-keyword">if</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">"can't convert #{opts.class} into Hash"</span> - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span>.<span class="ruby-identifier">configure</span>(<span class="ruby-identifier">opts</span>) - <span class="ruby-keyword">end</span> - <span class="ruby-identifier">state</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">obj</span>) -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - - <div class="method"> - <div class="title method-title" id="method-i-recurse_proc"> - - <a name="method-i-recurse_proc"></a><b>recurse_proc</b>(result, &proc) - - </div> - - - <div class="description"> - <p>Recursively calls passed <em>Proc</em> if the parsed data structure is an -<em>Array</em> or <em>Hash</em></p> - </div> - - - - - - - <div class="sourcecode"> - - <p class="source-link"> - Source: - <a href="javascript:toggleSource('method-i-recurse_proc_source')" id="l_method-i-recurse_proc_source">show</a> - - </p> - <div id="method-i-recurse_proc_source" class="dyn-source"> - <pre><span class="ruby-comment"># File lib/json/common.rb, line 326</span> -<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">recurse_proc</span>(<span class="ruby-identifier">result</span>, &<span class="ruby-identifier">proc</span>) - <span class="ruby-keyword">case</span> <span class="ruby-identifier">result</span> - <span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span> - <span class="ruby-identifier">result</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">recurse_proc</span> <span class="ruby-identifier">x</span>, &<span class="ruby-identifier">proc</span> } - <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">result</span> - <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span> - <span class="ruby-identifier">result</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">recurse_proc</span> <span class="ruby-identifier">x</span>, &<span class="ruby-identifier">proc</span>; <span class="ruby-identifier">recurse_proc</span> <span class="ruby-identifier">y</span>, &<span class="ruby-identifier">proc</span> } - <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">result</span> - <span class="ruby-keyword">else</span> - <span class="ruby-identifier">proc</span>.<span class="ruby-identifier">call</span> <span class="ruby-identifier">result</span> - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">end</span></pre> - </div> - </div> - - </div> - </div> - </div> - </body> -</html>
\ No newline at end of file |