You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/app/streamers/json_streamer.rb

29 lines
430 B
Ruby

class JsonStreamer
def initialize(object)
@object = object
end
def each(&blk)
yield '{'
@object.each_with_index do |key_value, i|
key, value = key_value
yield %("#{key}":)
if value.respond_to?(:call)
value.call do |v|
yield v.to_s
end
else
yield value.to_json
end
yield ',' unless i + 1 == @object.size
end
yield '}'
end
end