Class: Mirah::JavaSource::Output
- Inherits:
-
Object
- Object
- Mirah::JavaSource::Output
- Defined in:
- lib/mirah/jvm/source_generator/builder.rb
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #dedent ⇒ Object
- #indent ⇒ Object
-
#initialize ⇒ Output
constructor
A new instance of Output.
- #print(str) ⇒ Object
- #print_indent ⇒ Object
- #puts(*lines) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Output
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 |
#dedent ⇒ Object
98 99 100 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 98 def dedent @indent -= 2 end |
#indent ⇒ Object
94 95 96 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 94 def indent @indent += 2 end |
#print(str) ⇒ Object
89 90 91 92 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 89 def print(str) print_indent @out << str.to_s end |
#print_indent ⇒ Object
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_s ⇒ Object
110 111 112 |
# File 'lib/mirah/jvm/source_generator/builder.rb', line 110 def to_s @out end |