-
-
Save dipnlik/5c353d4bcbb564a7a8ca to your computer and use it in GitHub Desktop.
writing @output to a file with a custom output class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DoubleOutputter | |
def initialize(filename) | |
@file = File.new(filename, 'w+') | |
end | |
def puts(string) | |
@file.puts string | |
$stdout.puts string | |
end | |
def close | |
@file.close | |
end | |
end | |
@output = DoubleOutputter.new('dump.txt') | |
@output.puts "line 1" | |
@output.puts "line 2" | |
@output.puts "line 3" | |
@output.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment