Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
JSON::ResumableParser#empty?
empty?
ext/json/lib/json/ext.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/json/lib/json/ext.rb, line 130
def empty?
eos? && !partial_value? && !value?
end
Returns whether the parser is entirely done: no unconsumed bytes in the buffer, no document under construction and no parsed value awaiting retrieval.
The main use case is detecting a truncated stream once the input is exhausted:
Example
loop do begin parser << socket.readpartial(4096) rescue EOFError break end while parser.parse process(parser.value) end end warn "stream was truncated" unless parser.empty?