ox icon indicating copy to clipboard operation
ox copied to clipboard

`StringIO` in `Ox::Builder`

Open Yegorov opened this issue 2 years ago • 2 comments

Hello! It possible use StringIO in Ox::Builder?

require 'ox'
io = StringIO.new
b = Ox::Builder.io(io, indent: 2) # Here I get an exception: `io': expected an IO that has a fileno. (IOError)
10.times do
  b.element('node') do
    b.text('value')
  end
end
b.close
io.to_s

Yegorov avatar Jun 13 '22 09:06 Yegorov

Currently only files are supported. I'll looking into supporting anything that can be written to. Sorry for being slow to respond.

ohler55 avatar Jun 22 '22 18:06 ohler55

It would be too much of a change to support StringIO with little gain. Did you know you can create a new Builder without and io and it will build a string? Line 1472 of the test.rb file is an example of that.

ohler55 avatar Jun 22 '22 21:06 ohler55