Class: Async::IO::Protocol::Line
  
  
  
  
  
    - Inherits:
 
    - 
      Generic
      
        
          - Object
 
          
            - Wrapper
 
          
            - Generic
 
          
            - Async::IO::Protocol::Line
 
          
        
        show all
      
     
  
  
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/async/io/protocol/line.rb
 
  
  
 
  Constant Summary
  
  Constants inherited
     from Generic
  Generic::WRAPPERS
  Instance Attribute Summary collapse
  
  
  
  Attributes inherited from Generic
  #timeout
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Generic
  #<<, #connected?, #dup, #nonblock, #nonblock=, #nonblock?, #read, #readable?, #sysread, #syswrite, #wait, wrap, wrap_blocking_method, wraps, #write
  
  
  Constructor Details
  
    
  
  
    #initialize(stream, eol = $/)  ⇒ Line 
  
  
  
  
    
Returns a new instance of Line.
   
 
  
  
    
      
12
13
14
15
16 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 12
def initialize(stream, eol = $/)
	super(stream)
	
	@eol = eol
end 
     | 
  
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #eol  ⇒ Object  
  
  
  
  
    
Returns the value of attribute eol.
   
 
  
  
    
      
18
19
20 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 18
def eol
  @eol
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #each_line  ⇒ Object 
  
  
  
  
    
      
47
48
49
50
51
52
53 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 47
def each_line
	return to_enum(:each_line) unless block_given?
	
	while line = @stream.read_until(@eol)
		yield line
	end
end 
     | 
  
 
    
      
  
  
    #peek_line  ⇒ Object 
  
  
  
  
    
      
37
38
39
40
41
42
43
44
45 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 37
def peek_line
	@stream.peek do |read_buffer|
		if index = read_buffer.index(@eol)
			return read_buffer.slice(0, index)
		end
	end
	
	raise EOFError
end 
     | 
  
 
    
      
  
  
    #read_line  ⇒ Object 
  
  
  
  
    
      
33
34
35 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 33
def read_line
	@stream.read_until(@eol) or @stream.eof!
end 
     | 
  
 
    
      
  
  
    #read_lines  ⇒ Object 
  
  
  
  
    
      
55
56
57 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 55
def read_lines
	@stream.read.split(@eol)
end 
     | 
  
 
    
      
  
  
    #write_lines(*args)  ⇒ Object 
  
  
  
  
    
      
20
21
22
23
24
25
26
27
28
29
30
31 
     | 
    
      # File 'lib/async/io/protocol/line.rb', line 20
def write_lines(*args)
	if args.empty?
		@stream.write(@eol)
	else
		args.each do |arg|
			@stream.write(arg)
			@stream.write(@eol)
		end
	end
	
	@stream.flush
end 
     |