Sha256: bbb3ee63f06a68f15cb1b91120b24c48c42c9bfa2c834a69433fea2fbb04d964

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

# Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
# Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
# License::   LGPL
# $Id: ext.rb 567 2005-04-13 08:00:06Z polrop $


require 'delegate'

class IO
  module ImplIndent
    def indent(x='  ', &block)
      old = "#@indent"
#      p "old: `#@indent'"
      @indent += x.is_a?(Numeric) ? '  ' * x : x.to_s
#      p "ind: `#@indent'"
      yield(self)
      @indent = old
    end
  end

  module ImplPrintIO
    def print_io(io)
      io.each do |line|
	line.chomp!
	self.puts line
      end
    end
  end

  module ImplPrintFile
    def print_file(file)
      fh = File.new(file, 'r')
      self.print_io fh
      fh.close
    end
  end

  module ImplExt
    def dash
      self.puts '-'
    end

    include IO::ImplIndent
    include IO::ImplPrintIO
    include IO::ImplPrintFile
  end

  class Ext < DelegateClass(IO)
    include ImplIndent
  end
end


#FIXME: adapt me to a real unit test suite
# if __FILE__ == $0

#   class A < DelegateClass(IO) # :nodoc:
#     def syswrite(x)
#       super('--'+x)
#     end
#     def write(x)
#       super('--'+x)
#     end
#   end

#   a = A.new($stdout)

#   a << 'foo'

# end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ttk-0.1.576 lib/ttk/Tools/io/ext.rb
ttk-0.1.580 lib/ttk/Tools/io/ext.rb
ttk-0.1.579 lib/ttk/Tools/io/ext.rb