Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
JSON::ResumableParser#partial_value?
partial_value? → true or false
ext/json/parser/parser.c
View on GitHub ↗
static VALUE cResumableParser_partial_value_p(VALUE self)
{
JSON_ResumableParser *parser = cResumableParser_get(self);
// Mirror of #value?: values on the stack while the document isn't DONE
// belong to a partially built document. A container whose first key or
// element hasn't been parsed yet has no frame nor value registered (the
// tokenizer rewinds to the container start on EOS), so that state is
// observable through the buffer (#eos?/#rest) instead, keeping this
// predicate consistent with #partial_value returning nil.
if (parser->value_stack.head > 0) {
json_frame *frame = json_frame_stack_peek(&parser->frames);
if (frame->phase != JSON_PHASE_DONE) {
return Qtrue;
}
}
return Qfalse;
}
Returns whether a document is currently under construction: an unclosed container, a key awaiting its value, etc.
It answers the same question as !partial_value.nil?, but as a cheap predicate on the parser’s internal state, without materializing the partially parsed Ruby objects:
Example
parser << '{"a":1,' parser.parse # => false parser.partial_value? # => true
A fully parsed document whose value hasn’t been retrieved yet is not under construction: value? returns true and partial_value? returns false.