Module: Zip::IOExtras::AbstractOutputStream

Includes:
FakeIO
Included in:
OutputStream
Defined in:
lib/zip/ioextras/abstract_output_stream.rb

Overview

Implements many of the output convenience methods of IO. relies on <<

Instance Method Summary collapse

Methods included from FakeIO

#kind_of?

Instance Method Details



14
15
16
# File 'lib/zip/ioextras/abstract_output_stream.rb', line 14

def print(*params)
  self << params.join($,) << $\.to_s
end

#printf(a_format_string, *params) ⇒ Object



18
19
20
# File 'lib/zip/ioextras/abstract_output_stream.rb', line 18

def printf(a_format_string, *params)
  self << sprintf(a_format_string, *params)
end

#putc(an_object) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zip/ioextras/abstract_output_stream.rb', line 22

def putc(an_object)
  self << case an_object
          when Fixnum
            an_object.chr
          when String
            an_object
          else
            raise TypeError, 'putc: Only Fixnum and String supported'
          end
  an_object
end

#puts(*params) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/zip/ioextras/abstract_output_stream.rb', line 34

def puts(*params)
  params << "\n" if params.empty?
  params.flatten.each do |element|
    val = element.to_s
    self << val
    self << "\n" unless val[-1, 1] == "\n"
  end
end

#write(data) ⇒ Object



8
9
10
11
# File 'lib/zip/ioextras/abstract_output_stream.rb', line 8

def write(data)
  self << data
  data.to_s.bytesize
end