Project

tee

0.01
No commit activity in last 3 years
No release in over 3 years
A class like tee(1).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9.2.2
~> 2.11.0
 Project Readme

tee

A class like tee(1) for Ruby.

Build Status Coverage Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'tee'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tee

Examples

Basic usage

Tee.open('a.txt') do |tee|
  tee.puts 'foo'
end
# a.txt
foo

# STDOUT
foo

Multiple files

Tee.open('a.txt', 'b.txt') do |tee|
  tee.puts 'bar'
end
# a.txt
bar

# b.txt
bar

# STDOUT
bar

Appending mode

Tee.open('a.txt', mode: 'a') do |tee|
  tee.puts 'baz'
end
# a.txt
bar
baz

# STDOUT
baz

Disable STDOUT

Tee.open('a.txt', 'b.txt', stdout: nil) do |tee|
  tee.puts 'qux'
end
# a.txt
qux

# b.txt
qux

IO instances

require 'stringio'

stringio = StringIO.new

open('a.txt', 'w') do |file|
  Tee.open(file, stringio) do |tee|
    tee.puts 'quux'
  end  # `file` doesn't close because it wasn't opened by Tee.
  file.puts 'corge'
end

puts stringio.string
# a.txt
quux
corge

# STDOUT
quux
quux

Copyright

Copyright (c) 2012 Masaki Takeuchi. See LICENSE for details.