Project

General

Profile

Feature #5129

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

I suggest to create a class "`FileArray`" "FileArray" whose instance behaves just like `ARGF` ARGF do. 
 And I think `ARGF` ARGF should be an instance of `FileArray`. FileArray. Now when I "`p ARGF.class`", "p ARGF.class", I get "`ARGF.class`", "ARGF.class", so `ARGF` ARGF is an instance of `ARGF.class`, ARGF.class, how meaningless it is. 


 FileArray methods: 

 ```ruby 
 # create an instance 
 fa = FileArray.new('a.txt','b.txt','c.txt') 

 # take many methods from IO 
 # most methods from ARGF should be instance methods of ARGF  
 fa.each {|line| puts line } 
 fa.realines 
 fa.filename # current file 

 # but "argv" not 
 p fa.file_list # in ARGF, its ARGF.argv, but #argv is not a proper name for FileArray 

 # ARGV array can be modified, adding new file into it, all replace to a new file list. 
 # FileArray should add some methods to modify the inner file list. 
 fa.insert(3,"d.txt") 
 fa.delete('a.txt') 
 ``` 

 


 With `FileArray`, FileArray, You can create multiple `ARGF`-like ARGF-like file arrays simultaneously. 

 For example, I want to mix two *groups* of files, not two files: 

 ```ruby 
 a_files = FileArray.new(*Dir.glob('a*.txt')) 
 b_files = FileArray.new(*Dir.glob('b*.txt')) 

 enum_a = a_files.each 
 enum_b = b_files.each 

 loop do 
  puts enum_a.next 
  puts enum_b.next 
 end 
 ```

Back