Skip to content

Commit

Permalink
Add some JSON::Fragment documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 21, 2025
1 parent 8f1bba3 commit dbcf614
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/json/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ def detailed_message(...)
# 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
Expand Down

0 comments on commit dbcf614

Please sign in to comment.