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.



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

#dedentObject



73
74
75
# File 'lib/duby/jvm/source_generator/builder.rb', line 73

def dedent
  @indent -= 2
end

#indentObject



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

def indent
  @indent += 2
end


64
65
66
67
# File 'lib/duby/jvm/source_generator/builder.rb', line 64

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


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_sObject



85
86
87
# File 'lib/duby/jvm/source_generator/builder.rb', line 85

def to_s
  @out
end