File: with_different_ofs.rb

package info (click to toggle)
ruby-csv 3.3.5-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 796 kB
  • sloc: ruby: 6,862; makefile: 4; sh: 4
file content (34 lines) | stat: -rw-r--r-- 722 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module DifferentOFS
  is_output_field_separator_deprecated = false
  verbose, $VERBOSE = $VERBOSE, true
  stderr, $stderr = $stderr, StringIO.new
  begin
    ofs, $, = $,, "-"
    is_output_field_separator_deprecated = (not $stderr.string.empty?)
  ensure
    $, = ofs
    $stderr = stderr
    $VERBOSE = verbose
  end

  unless is_output_field_separator_deprecated
    module WithDifferentOFS
      def setup
        super
        @ofs, $, = $,, "-"
      end

      def teardown
        $, = @ofs
        super
      end
    end

    def self.extended(klass)
      super(klass)
      klass.const_set(:DifferentOFS, Class.new(klass).class_eval {include WithDifferentOFS})
    end
  end
end