Skip to content

Commit dbcf614

Browse files
committed
Add some JSON::Fragment documentation
1 parent 8f1bba3 commit dbcf614

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/json/common.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ def detailed_message(...)
167167
# system. Usually this means that the iconv library is not installed.
168168
class MissingUnicodeSupport < JSONError; end
169169

170+
# Fragment of JSON document that is to be included as is:
171+
# fragment = JSON::Fragment.new("[1, 2, 3]")
172+
# JSON.generate({ count: 3, items: fragments })
173+
#
174+
# This allows to easily assemble multiple JSON fragments that have
175+
# been peristed somewhere without having to parse them nor resorting
176+
# to string interpolation.
170177
Fragment = Struct.new(:json) do
171178
def to_json(state = nil, *)
172179
json

0 commit comments

Comments
 (0)