Class: JSON::Fragment
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Struct
|
|
|
Instance Chain:
self,
Struct
|
|
| Inherits: |
Struct
|
| Defined in: | ext/json/lib/json/common.rb |
Overview
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 persisted somewhere without having to parse them nor resorting
to string interpolation.
Note: no validation is performed on the provided string. It is the
responsibility of the caller to ensure the string contains valid ::JSON.
Class Method Summary
- .new(json) ⇒ Fragment constructor
Instance Attribute Summary
Instance Method Summary
Constructor Details
.new(json) ⇒ Fragment
Instance Attribute Details
#json (rw)
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 persisted somewhere without having to parse them nor resorting
to string interpolation.
Note: no validation is performed on the provided string. It is the
responsibility of the caller to ensure the string contains valid ::JSON.
# File 'ext/json/lib/json/common.rb', line 232
Fragment = Struct.new(:json)