Class: StringOutput

Inherits:
Object show all
Defined in:
lib/tmail/stringio.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ StringOutput

Returns a new instance of StringOutput.



196
197
198
199
# File 'lib/tmail/stringio.rb', line 196

def initialize( str = '' )
  @dest = str
  @closed = false
end

Class Method Details

.new(str = '') ⇒ Object Also known as: open



179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/tmail/stringio.rb', line 179

def new( str = '' )
  if block_given?
    begin
      f = super
      yield f
    ensure
      f.close if f
    end
  else
    super
  end
end

Instance Method Details

#<<(str) ⇒ Object



267
268
269
270
271
# File 'lib/tmail/stringio.rb', line 267

def <<( str )
  stream_check!
  @dest << str.to_s
  self
end

#closeObject



201
202
203
# File 'lib/tmail/stringio.rb', line 201

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/tmail/stringio.rb', line 205

def closed?
  @closed
end

#inspectObject



222
223
224
# File 'lib/tmail/stringio.rb', line 222

def inspect
  "#<#{self.class}:#{@dest ? 'open' : 'closed'},#{object_id}>"
end

Raises:

  • (ArgumentError)


226
227
228
229
230
231
232
233
234
# File 'lib/tmail/stringio.rb', line 226

def print( *args )
  stream_check!
  raise ArgumentError, 'wrong # of argument (0 for >1)' if args.empty?
  args.each do |s|
    raise ArgumentError, 'nil not allowed' if s.nil?
    @dest << s.to_s
  end
  nil
end

#printf(*args) ⇒ Object



252
253
254
255
256
# File 'lib/tmail/stringio.rb', line 252

def printf( *args )
  stream_check!
  @dest << sprintf(*args)
  nil
end

#putc(ch) ⇒ Object



246
247
248
249
250
# File 'lib/tmail/stringio.rb', line 246

def putc( ch )
  stream_check!
  @dest << ch.chr
  nil
end

#puts(*args) ⇒ Object



236
237
238
239
240
241
242
243
244
# File 'lib/tmail/stringio.rb', line 236

def puts( *args )
  stream_check!
  args.each do |str|
    @dest << (s = str.to_s)
    @dest << "\n" unless s[-1] == ?\n
  end
  @dest << "\n" if args.empty?
  nil
end

#sizeObject Also known as: pos



216
217
218
# File 'lib/tmail/stringio.rb', line 216

def size
  @dest.size
end

#stringObject Also known as: value, to_str



209
210
211
# File 'lib/tmail/stringio.rb', line 209

def string
  @dest
end

#write(str) ⇒ Object Also known as: syswrite



258
259
260
261
262
263
# File 'lib/tmail/stringio.rb', line 258

def write( str )
  stream_check!
  s = str.to_s
  @dest << s
  s.size
end