summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-01-21 08:52:04 +0100
committerHiroshi SHIBATA <[email protected]>2025-01-28 15:39:17 +0900
commit77af41ea6525d94ac3bc97ddbdbceb8665d397ca (patch)
tree0e2ee2b58d1feb94a0267857d880de37b37e3a23
parent53f0ebf938539e7ee847d1f900ac793d9cd9825a (diff)
[ruby/json] Add some JSON::Fragment documentation
https://github.com/ruby/json/commit/dbcf614e50
-rw-r--r--ext/json/lib/json/common.rb7
1 files changed, 7 insertions, 0 deletions
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