summaryrefslogtreecommitdiff
path: root/usage.incl
blob: 1497346484427847963970ece38acc59a4c525f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<h2>Usage</h2>
<p>
If you require JSON like this:
</p>
<pre>
require 'json'
</pre>
<p>
JSON first tries to load the extension variant. If this fails, the pure variant
is loaded and used.
</p>
<p>
To determine, which variant is active you can use the follwing methods:
</p>
<ul>
<li>Ext variant:
<pre>
\[ JSON.parser, JSON.generator ] # => \[JSON::Ext::Parser, JSON::Ext::Generator]
</pre>
</li>
<li>Pure variant:
<pre>
\[ JSON.parser, JSON.generator ] # => \[JSON::Pure::Parser, JSON::Pure::Generator]
</pre>
</li>
</ul>
<p>
If you want to enforce loading of a special variant, use
</p>
<pre>
require 'json/ext'
</pre>
<p>
to load the extension variant. Or use
</p>
<pre>
require 'json/pure'
</pre>
<p>
to use the pure variant.
</p>
<p>
You can choose to load a set of common additions to ruby core's objects if you
</p>
<pre>
  require 'json/add/core'
</pre>
<p>
  To get the best compatibility to rails' JSON implementation, you can
</p>
<pre>
    require 'json/add/rails'
</pre> 
<p>
    Both of the additions attempt to require 'json' (like above) first, if it has not been required yet. 
</p>