Class: Recls::FileSearchLineEnumerator
- Inherits:
-
Object
- Object
- Recls::FileSearchLineEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/recls/foreach.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(fs) ⇒ FileSearchLineEnumerator
constructor
A new instance of FileSearchLineEnumerator.
Constructor Details
#initialize(fs) ⇒ FileSearchLineEnumerator
Returns a new instance of FileSearchLineEnumerator.
48 49 50 51 |
# File 'lib/recls/foreach.rb', line 48 def initialize(fs) @fs = fs end |
Instance Method Details
#each(&block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/recls/foreach.rb', line 53 def each(&block) @fs.each do |fe| IO::readlines(fe).each_with_index do |line, index| case block.arity when 1 yield line when 2 yield line, index when 3 yield line, index, fe else raise ArgumentError, "block must take 1, 2, or 3 parameters - #{block.arity} given. (Perhaps you have applied each_with_index, which cannot be done to Recls.foreach)" end end end end |