Sha256: b89ffd304a3383281e033687e067c5b9c072f5f060cc6eac62bc51fef164b153
Contents?: true
Size: 1.27 KB
Versions: 142
Compression:
Stored size: 1.27 KB
Contents
require 'stringio' # Kernel module Kernel # capture STDOUT # # # capture print # print capture_stdout { print "hoge" } # => hoge # # if block have no STDOUT, capture_stdout returns empty. # print capture_stdout { }.empty? # => true def capture_stdout begin $stdout = StringIO.new yield result = $stdout.string ensure $stdout = STDOUT end result end # debug print line for print-debugging # # # debug print default # dp_line __LINE__ # # yy = call line no # # => --------------------|filename=|line=yy|-------------------- # # debug print with filename # dp_line __LINE__, filename: __FILE__ # # xx = filename, yy = call line no # # => --------------------|filename=xx|line=yy|-------------------- # # debug print with no filename, specific char # dp_line __LINE__, char: '@' # # xx = filename, yy = call line no # # => @@@@@@@@@@@@@@@@@@@@|filename=|line=yy|@@@@@@@@@@@@@@@@@@@@ def dp_line(line, options = { filename: '', char: '-' }) filename = options[:filename].nil? ? '' : options[:filename] char = options[:char].nil? ? '-' : options[:char] puts "#{char * 20}|filename=#{filename}|line=#{line}|#{char * 20}" end end
Version data entries
142 entries across 142 versions & 1 rubygems
Version | Path |
---|---|
tbpgr_utils-0.0.11 | lib/test_toolbox/kernel.rb |
tbpgr_utils-0.0.10 | lib/test_toolbox/kernel.rb |