Module: Output
- Defined in:
- lib/start.rb
Overview
ログ出力
Class Method Summary collapse
Class Method Details
.console_and_file(output_file, stdout = true) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/start.rb', line 15 def self.console_and_file(output_file, stdout = true) begin defout = File.new(output_file, "a+") rescue puts $! puts $@ return nil end class << defout alias_method :write_org, :write def initialize(stdout) @stdout = false end attr_accessor :stdout def puts(str) STDOUT.write(str.to_s + "\n") if @stdout self.write_org(str.to_s + "\n") self.flush end def write(str) STDOUT.write(str) if @stdout self.write_org(str) self.flush end end $stdout = defout $stdout.stdout = stdout end |