Class: 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.
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 |
#dedent ⇒ Object
71 72 73 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 71 def dedent @indent -= 2 end |
#indent ⇒ Object
67 68 69 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 67 def indent @indent += 2 end |
#print(str) ⇒ Object
62 63 64 65 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 62 def print(str) print_indent @out << str.to_s end |
#print_indent ⇒ Object
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_s ⇒ Object
83 84 85 |
# File 'lib/duby/jvm/source_generator/builder.rb', line 83 def to_s @out end |