Class: Duby::JavaSource::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/duby/jvm/source_generator/builder.rb

Instance Method Summary collapse

Constructor Details

#initializeOutput

Returns a new instance of Output.



42
43
44
45
# File 'lib/duby/jvm/source_generator/builder.rb', line 42

def initialize
  @out = ""
  @indent = 0
end

Instance Method Details

#<<(other) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/duby/jvm/source_generator/builder.rb', line 75

def <<(other)
  other.to_s.each_line do |line|
    print_indent
    print(line)
    @indented = false
  end
end

#dedentObject



71
72
73
# File 'lib/duby/jvm/source_generator/builder.rb', line 71

def dedent
  @indent -= 2
end

#indentObject



67
68
69
# File 'lib/duby/jvm/source_generator/builder.rb', line 67

def indent
  @indent += 2
end


62
63
64
65
# File 'lib/duby/jvm/source_generator/builder.rb', line 62

def print(str)
  print_indent
  @out << str.to_s
end


56
57
58
59
60
# File 'lib/duby/jvm/source_generator/builder.rb', line 56

def print_indent
  @indent ||= 0
  @out << (' ' * @indent) unless @indented
  @indented = true
end

#puts(*lines) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/duby/jvm/source_generator/builder.rb', line 47

def puts(*lines)
  lines.each do |line|
    print_indent
    @out << line.to_s
    @out << "\n"
    @indented = false
  end
end

#to_sObject



83
84
85
# File 'lib/duby/jvm/source_generator/builder.rb', line 83

def to_s
  @out
end