Class: AlFuncTest::EmulateStdin

Inherits:
Object
  • Object
show all
Defined in:
lib/al_functest.rb

Overview

Note:

stdinエミュレートクラス

Aloneで必要な最小限の機能のみ実装する。

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (EmulateStdin) initialize(s = "")

Returns a new instance of EmulateStdin



377
378
379
380
# File 'lib/al_functest.rb', line 377

def initialize( s = "" )
  @buffer = s
  @buffer.force_encoding( Encoding::ASCII_8BIT )
end

Instance Attribute Details

- (Object) buffer

Returns the value of attribute buffer



375
376
377
# File 'lib/al_functest.rb', line 375

def buffer
  @buffer
end

Instance Method Details

- (Object) content_length



397
398
399
# File 'lib/al_functest.rb', line 397

def content_length()
  return @buffer.length.to_s
end

- (Object) gets



387
388
389
390
391
392
393
394
395
# File 'lib/al_functest.rb', line 387

def gets()
  idx = @buffer.index( "\n" )
  return @buffer.slice!( 0, idx+1 ) if idx
  return nil if @buffer.empty?
  
  ret = @buffer
  @buffer = ""
  return ret
end

- (Object) read(length)



382
383
384
385
# File 'lib/al_functest.rb', line 382

def read( length )
  ret = @buffer.slice!( 0, length )
  return ret
end