Method: CodeOutput::Parser#initialize
- Defined in:
- lib/code_output.rb
#initialize(filename) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/code_output.rb', line 8 def initialize filename @filename = File.(filename) raise IOError, "`#{filename}' is not readable" unless File.readable? filename @old_stdout = $stdout $stdout = StringIO.new $stdout.instance_eval do class << self attr_accessor :outputs alias_method :old_write, :write def write string (@outputs ||= []) << { line: caller.first, string: string } old_write string end end end end |