lib/rbbt/tsv/accessor.rb in rbbt-util-5.13.37 vs lib/rbbt/tsv/accessor.rb in rbbt-util-5.14.0
- old
+ new
@@ -522,23 +522,12 @@
else
"\t" << values.to_s << "\n"
end
end
- def to_s(keys = nil, no_options = false)
- if FalseClass === keys or TrueClass === keys
- no_options = keys
- keys = nil
- end
-
- if keys == :sort
- with_unnamed do
- keys = self.keys.sort
- end
- end
-
- io = TSV::Dumper.stream self do |dumper|
+ def dumper_stream(keys = nil, no_options = false)
+ TSV::Dumper.stream self do |dumper|
dumper.init unless no_options
begin
if keys
keys.each do |key|
dumper.add key, self[key]
@@ -552,10 +541,26 @@
end
rescue Exception
Log.exception $!
raise $!
end
+ dumper.close
end
+ end
+
+ def to_s(keys = nil, no_options = false)
+ if FalseClass === keys or TrueClass === keys
+ no_options = keys
+ keys = nil
+ end
+
+ if keys == :sort
+ with_unnamed do
+ keys = self.keys.sort
+ end
+ end
+
+ io = dumper_stream(keys, no_options)
str = ''
while block = io.read(2048)
str << block
end