class JsonEmitter::Stream
Represents a stream of JSON to be generated and yielded. It can be treated like any Enumerable. Unlike UnbufferedStream, the size of the yielded strings can vary from 1 to 1000's.
Public Class Methods
new(enum)
click to toggle source
Initialize a new stream.
@param enum [Enumerator] An enumerator that yields pieces of JSON.
# File lib/json-emitter/stream.rb, line 14 def initialize(enum) @enum = enum end
Public Instance Methods
each() { |str| ... }
click to toggle source
If a block is given, each chunk of JSON is yielded to it. If not block is given, an Enumerator is returned.
@return [Enumerator]
# File lib/json-emitter/stream.rb, line 34 def each if block_given? @enum.each { |str| yield str } else @enum end end
write(io)
click to toggle source
Write the stream to the specified IO object.
@param io [IO]
# File lib/json-emitter/stream.rb, line 23 def write(io) each { |str| io << str } end