Skip to content

Commit 470d909

Browse files
committed
RDoc enhancements
1 parent 7bee2c7 commit 470d909

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

lib/json.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
#
8383
# \String:
8484
# ruby = JSON.parse('"foo"')
85-
# ruby # => "foo"
85+
# ruby # => 'foo'
8686
# ruby.class # => String
8787
# \Integer:
8888
# ruby = JSON.parse('1')
@@ -121,27 +121,27 @@
121121
# a \String containing a \JSON array:
122122
# ruby = [0, 's', :foo]
123123
# json = JSON.generate(ruby)
124-
# json # => "[0,\"s\",\"foo\"]"
124+
# json # => '[0,"s","foo"]'
125125
#
126126
# The Ruby \Array array may contain nested arrays, hashes, and scalars
127127
# to any depth:
128128
# ruby = [0, [1, 2], {foo: 3, bar: 4}]
129129
# json = JSON.generate(ruby)
130-
# json # => "[0,[1,2],{\"foo\":3,\"bar\":4}]"
130+
# json # => '[0,[1,2],{"foo":3,"bar":4}]'
131131
#
132132
# ==== Generating \JSON from Hashes
133133
#
134134
# When the source is a Ruby \Hash, JSON.generate returns
135135
# a \String containing a \JSON object:
136136
# ruby = {foo: 0, bar: 's', baz: :bat}
137137
# json = JSON.generate(ruby)
138-
# json # => "{\"foo\":0,\"bar\":\"s\",\"baz\":\"bat\"}"
138+
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
139139
#
140140
# The Ruby \Hash array may contain nested arrays, hashes, and scalars
141141
# to any depth:
142142
# ruby = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
143143
# json = JSON.generate(ruby)
144-
# json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
144+
# json # => '{"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}'
145145
#
146146
# ==== Generating \JSON from Other Objects
147147
#
@@ -150,34 +150,34 @@
150150
#
151151
# When the source is a Ruby \Integer or \Float, JSON.generate returns
152152
# a \String containing a \JSON number:
153-
# JSON.generate(42) # => "42"
154-
# JSON.generate(0.42) # => "0.42"
153+
# JSON.generate(42) # => '42'
154+
# JSON.generate(0.42) # => '0.42'
155155
#
156156
# When the source is a Ruby \String, JSON.generate returns
157157
# a \String containing a \JSON string (with double-quotes):
158-
# JSON.generate('A string') # => "\"A string\""
158+
# JSON.generate('A string') # => '"A string"'
159159
#
160160
# When the source is +true+, +false+ or +nil+, JSON.generate returns
161161
# a \String containing the corresponding \JSON token:
162-
# JSON.generate(true) # => "true"
163-
# JSON.generate(false) # => "false"
164-
# JSON.generate(nil) # => "null"
162+
# JSON.generate(true) # => 'true'
163+
# JSON.generate(false) # => 'false'
164+
# JSON.generate(nil) # => 'null'
165165
#
166166
# When the source is none of the above, JSON.generate returns
167167
# a \String containing a \JSON string representation of the source:
168-
# JSON.generate(:foo) # => "\"foo\""
169-
# JSON.generate(Complex(0, 0)) # => "\"0+0i\""
170-
# JSON.generate(Dir.new('.')) # => "\"#<Dir:0x0000000006bb30b8>\""
168+
# JSON.generate(:foo) # => '"foo"'
169+
# JSON.generate(Complex(0, 0)) # => '"0+0i"'
170+
# JSON.generate(Dir.new('.')) # => '"#<Dir>"'
171171
#
172172
# == \JSON Additions
173173
#
174174
# When you "round trip" a non-\String object from Ruby to \JSON and back,
175175
# you have a new \String, instead of the object you began with:
176176
# ruby0 = Range.new(0, 2)
177177
# json = JSON.generate(ruby0)
178-
# json # => "\"0..2\""
178+
# json # => '0..2"'
179179
# ruby1 = JSON.parse(json)
180-
# ruby1 # => "0..2"
180+
# ruby1 # => '0..2'
181181
# ruby1.class # => String
182182
#
183183
# You can use \JSON _additions_ to preserve the original object.

lib/json/common.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class << self
1212
#
1313
# Otherwise, calls JSON.generate with +object+ and +opts+:
1414
# ruby = [0, 1, nil]
15-
# JSON[ruby] # => "[0,1,null]"
15+
# JSON[ruby] # => '[0,1,null]'
1616
def [](object, opts = {})
1717
if object.respond_to? :to_str
1818
JSON.parse(object.to_str, opts)
@@ -99,7 +99,7 @@ def generator=(generator) # :nodoc:
9999

100100
# Sets or returns create identifier, which is used to decide if the _json_create_
101101
# hook of a class should be called; initial value is +json_class+:
102-
# JSON.create_id # => "json_class"
102+
# JSON.create_id # => 'json_class'
103103
attr_accessor :create_id
104104
end
105105
self.create_id = 'json_class'
@@ -309,14 +309,14 @@ def parse!(source, opts = {})
309309
# (implementing +to_ary+), returns a \String containing a \JSON array:
310310
# obj = ["foo", 1.0, true, false, nil]
311311
# json = JSON.generate(obj)
312-
# json # => "[\"foo\",1.0,true,false,null]"
312+
# json # => '["foo",1.0,true,false,null]'
313313
#
314314
# When +obj+ is a
315315
# {Hash-convertible object}[doc/implicit_conversion_rdoc.html#label-Hash-Convertible+Objects],
316316
# return a \String containing a \JSON object:
317317
# obj = {foo: 0, bar: 's', baz: :bat}
318318
# json = JSON.generate(obj)
319-
# json # => "{\"foo\":0,\"bar\":\"s\",\"baz\":\"bat\"}"
319+
# json # => '{"foo":0,"bar":"s","baz":"bat"}'
320320
#
321321
# For examples of generating from other Ruby objects, see
322322
# {Generating \JSON from Other Objects}[#module-JSON-label-Generating+JSON+from+Other+Objects].
@@ -337,7 +337,7 @@ def parse!(source, opts = {})
337337
#
338338
# Allow:
339339
# ruby = [Float::NaN, Float::Infinity, Float::MinusInfinity]
340-
# JSON.generate(ruby, allow_nan: true) # => "[NaN,Infinity,-Infinity]"
340+
# JSON.generate(ruby, allow_nan: true) # => '[NaN,Infinity,-Infinity]'
341341
#
342342
# ---
343343
#
@@ -346,7 +346,7 @@ def parse!(source, opts = {})
346346
#
347347
# With the default, +100+:
348348
# obj = [[[[[[0]]]]]]
349-
# JSON.generate(obj) # => "[[[[[[0]]]]]]"
349+
# JSON.generate(obj) # => '[[[[[[0]]]]]]'
350350
#
351351
# Too deep:
352352
# # Raises JSON::NestingError (nesting of 2 is too deep):

0 commit comments

Comments
 (0)