Class: JoinedInput
- Inherits:
- 
      Object
      
        - Object
- JoinedInput
 
- Defined in:
- lib/pslm/joinedinput.rb
Overview
“joins” several input streams, so that #gets behaves as if they were a single stream
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #gets ⇒ Object
- 
  
    
      #initialize(*ins)  ⇒ JoinedInput 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    accepts any number of open IOs. 
- #read ⇒ Object
Constructor Details
#initialize(*ins) ⇒ JoinedInput
accepts any number of open IOs
| 8 9 10 | # File 'lib/pslm/joinedinput.rb', line 8 def initialize(*ins) @streams = ins end | 
Instance Method Details
#close ⇒ Object
| 34 35 36 37 | # File 'lib/pslm/joinedinput.rb', line 34 def close @streams.each {|s| s.close } @streams = [] end | 
#closed? ⇒ Boolean
| 39 40 41 | # File 'lib/pslm/joinedinput.rb', line 39 def closed? @streams.empty? end | 
#gets ⇒ Object
| 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # File 'lib/pslm/joinedinput.rb', line 12 def gets if @streams.empty? then return nil end l = @streams.first.gets if l == nil @streams.shift return gets end unless l.end_with? "\n" l += "\n" end return l end | 
#read ⇒ Object
| 30 31 32 | # File 'lib/pslm/joinedinput.rb', line 30 def read @streams.collect {|s| s.read }.join "\n" end |