1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
class PrintFile
def initialize(name)
@depth = 0
@name = name
@file = createFile(name)
end
def createFile(name)
attr = File::CREAT|File::TRUNC|File::RDWR
File.new(name, attr, 0644)
end
def tabs
return "" if @depth == 0
count = 0
result = ""
while (count != @depth)
result += " "
count += 1
end
return result
end
def indent
@depth += 1
end
def dedent
return if @depth == 0
@depth -= 1
end
def printInline(*values)
@file.print values
end
def putsInline(*values)
@file.puts(values)
end
def print(*values)
if(values.length == 0)
return
end
@file.print tabs
@file.print values
end
def puts(*values)
if(values.length == 0)
@file.puts
return
end
@file.print tabs
@file.puts values
end
def close
@file.close
end
end
|