Project

General

Profile

Actions

Feature #5129

open

Create a core class "FileArray" and make "ARGF" its instance

Feature #5129: Create a core class "FileArray" and make "ARGF" its instance

Added by yimutang (Joey Zhou) over 14 years ago. Updated almost 8 years ago.

Status:
Assigned
Target version:
-
[ruby-core:38644]

Description

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

FileArray methods:

# 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, You can create multiple ARGF-like file arrays simultaneously.

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

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 

Updated by mame (Yusuke Endoh) over 13 years ago Actions #1 [ruby-core:43698]

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

Hello,

I like the idea, but it requires matz's approval.

Now when I "p ARGF.class", I get "ARGF.class", so ARGF is an instance of ARGF.class, how meaningless it is.

FYI: In fact, it is meaningful. You can "exploit" it.

$ cat a.txt foo $ cat b.txt bar $ ruby -e 'p ARGF.class.new("a.txt", "b.txt").read' "foo\nbar\n" 

I'm not sure if this behavior is the spec, though.

--
Yusuke Endoh

Updated by mame (Yusuke Endoh) almost 13 years ago Actions #2

  • Target version set to 2.6

Updated by naruse (Yui NARUSE) almost 8 years ago Actions #3

  • Target version deleted (2.6)

Updated by shevegen (Robert A. Heiler) almost 8 years ago Actions #4 [ruby-core:84986]

Just noticed it for the upcoming developer meeting. I agree with the
functionality; not sure if FileArray is a good name, but I also can
not suggest a better name. (The functionality is fine in my opinion)

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago Actions #5 [ruby-core:84993]

  • Description updated (diff)

yimutang (Joey Zhou) wrote:

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

FileGroup ?

Actions

Also available in: PDF Atom