Class: HelpfulComments::FileWrapper
- Inherits:
-
Object
- Object
- HelpfulComments::FileWrapper
- Defined in:
- lib/helpful_comments/file_wrapper.rb
Instance Method Summary collapse
-
#initialize(file, max_lines) ⇒ FileWrapper
constructor
build a new file wrapper.
-
#trailing?(lines) ⇒ Boolean
true if the last written lines to the file match the given lines.
-
#write(string) ⇒ Object
write the line to the file.
Constructor Details
#initialize(file, max_lines) ⇒ FileWrapper
build a new file wrapper
4 5 6 7 |
# File 'lib/helpful_comments/file_wrapper.rb', line 4 def initialize(file, max_lines) @file = file @lines = Array.new(max_lines, '') end |
Instance Method Details
#trailing?(lines) ⇒ Boolean
true if the last written lines to the file match the given lines
10 11 12 13 |
# File 'lib/helpful_comments/file_wrapper.rb', line 10 def trailing?(lines) raise ArgumentError, 'lines too long' if lines.size > @lines.size @lines[(@lines.size - lines.size)..-1] == lines end |
#write(string) ⇒ Object
write the line to the file
16 17 18 19 20 |
# File 'lib/helpful_comments/file_wrapper.rb', line 16 def write(string) @lines.shift @lines << string @file.write(string) end |