From 77af41ea6525d94ac3bc97ddbdbceb8665d397ca Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Tue, 21 Jan 2025 08:52:04 +0100 Subject: [PATCH] [ruby/json] Add some JSON::Fragment documentation https://github.com/ruby/json/commit/dbcf614e50 --- ext/json/lib/json/common.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index a9682b94cf..ea15b70686 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -167,6 +167,13 @@ module JSON # system. Usually this means that the iconv library is not installed. class MissingUnicodeSupport < JSONError; end + # Fragment of JSON document that is to be included as is: + # fragment = JSON::Fragment.new("[1, 2, 3]") + # JSON.generate({ count: 3, items: fragments }) + # + # This allows to easily assemble multiple JSON fragments that have + # been peristed somewhere without having to parse them nor resorting + # to string interpolation. Fragment = Struct.new(:json) do def to_json(state = nil, *) json