lib/rbbt/tsv/manipulate.rb in rbbt-util-5.19.20 vs lib/rbbt/tsv/manipulate.rb in rbbt-util-5.19.21

- old
+ new

@@ -240,11 +240,11 @@ [traverser.new_key_field_name, traverser.new_field_names] end def reorder(new_key_field = nil, new_fields = nil, options = {}) - zipped, uniq = Misc.process_options options, :zipped, :uniq + zipped, uniq, merge = Misc.process_options options, :zipped, :uniq, :merge persist_options = Misc.pull_keys options, :persist persist_options[:prefix] = "Reorder" Persist.persist_tsv self, self.filename, self.options.merge({:key_field => new_key_field, :fields => new_fields}), persist_options do |data| @@ -255,10 +255,18 @@ new_key_field_name, new_field_names = nil, nil with_unnamed do if zipped or (type != :double and type != :flat) new_key_field_name, new_field_names = through new_key_field, new_fields, uniq, zipped do |key, value| - data[key] = value.clone if Array === value + if merge and data[key] + new_values = data[key].dup + value.each_with_index do |v,i| + new_values[i] = [new_values[i], v].flatten + end + data[key] = new_values if Array === value + else + data[key] = value.clone if Array === value + end end else case type when :double new_key_field_name, new_field_names = through new_key_field, new_fields, uniq, zipped do |keys, value|