Class: Duby::JavaSource::Output
- Inherits:
-
Object
- Object
- Duby::JavaSource::Output
- Defined in:
- lib/duby/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.
44 45 46 47 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 44 def initialize @out = "" @indent = 0 end |
Instance Method Details
#<<(other) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 77 def <<(other) other.to_s.each_line do |line| print_indent print(line) @indented = false end end |
#dedent ⇒ Object
73 74 75 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 73 def dedent @indent -= 2 end |
#indent ⇒ Object
69 70 71 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 69 def indent @indent += 2 end |
#print(str) ⇒ Object
64 65 66 67 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 64 def print(str) print_indent @out << str.to_s end |
#print_indent ⇒ Object
58 59 60 61 62 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 58 def print_indent @indent ||= 0 @out << (' ' * @indent) unless @indented @indented = true end |
#puts(*lines) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 49 def puts(*lines) lines.each do |line| print_indent @out << line.to_s @out << "\n" @indented = false end end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 85 def to_s @out end |