Class: Mirah::JavaSource::Output

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

Instance Method Summary collapse

Constructor Details

#initializeOutput

Returns a new instance of Output.



69
70
71
72
# File 'lib/mirah/jvm/source_generator/builder.rb', line 69

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

Instance Method Details

#<<(other) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/mirah/jvm/source_generator/builder.rb', line 102

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

#dedentObject



98
99
100
# File 'lib/mirah/jvm/source_generator/builder.rb', line 98

def dedent
  @indent -= 2
end

#indentObject



94
95
96
# File 'lib/mirah/jvm/source_generator/builder.rb', line 94

def indent
  @indent += 2
end


89
90
91
92
# File 'lib/mirah/jvm/source_generator/builder.rb', line 89

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


83
84
85
86
87
# File 'lib/mirah/jvm/source_generator/builder.rb', line 83

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

#puts(*lines) ⇒ Object



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

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

#to_sObject



110
111
112
# File 'lib/mirah/jvm/source_generator/builder.rb', line 110

def to_s
  @out
end