Sha256: 1a063c364b440ab947a7edcf7d6c28a58ac10dad77fc3e30bfb94a2da99b50a4
Contents?: true
Size: 677 Bytes
Versions: 1
Compression:
Stored size: 677 Bytes
Contents
class Masticate::Base attr_reader :filename attr_reader :input, :output attr_reader :input_count, :output_count def initialize(filename) @filename = filename end def with_input @input = @filename ? open(@filename) : $stdin @input_count = 0 result = yield @input @input.close if @filename result end def get line = @input.gets @input_count += 1 line && line.chomp end def emit(line) @output_count += 1 begin @output.puts line rescue Errno::EPIPE # output was closed, e.g. ran piped into `head` # silently ignore this condition, it's not fatal and doesn't need a warning end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
masticate-0.1.0 | lib/masticate/base.rb |