class Unparser::Buffer
Buffer used to emit into
def append(string)
- Api: - private
Returns:
-
(self)
-
Parameters:
-
string
(String
) --
def append(string) if @content[-1].eql?(NL) prefix end write(string) self end
def append_without_prefix(string)
- Api: - private
Returns:
-
(self)
-
Parameters:
-
string
(String
) --
def append_without_prefix(string) write(string) end
def content
- Api: - private
Returns:
-
(String)
-
def content @content.dup.freeze end
def ensure_nl
def ensure_nl nl unless fresh_line? end
def final_newline
def final_newline return if fresh_line? || @no_nl write(NL) end
def flush_heredocs
def flush_heredocs @heredocs.each(&public_method(:write)) @heredocs = [] end
def fresh_line?
- Api: - private
Returns:
-
(Boolean)
-
def fresh_line? @content.empty? || @content[-1].eql?(NL) end
def indent
- Api: - private
Returns:
-
(self)
-
def indent @indent += 1 self end
def initialize
- Api: - private
Returns:
-
(undefined)
-
def initialize @content = +'' @heredocs = [] @indent = 0 @no_nl = true end
def nl
- Api: - private
Returns:
-
(self)
-
def nl @no_nl = false write(NL) flush_heredocs self end
def nl_flush_heredocs
def nl_flush_heredocs return if @heredocs.empty? if fresh_line? flush_heredocs else nl end end
def prefix
def prefix write(INDENT_SPACE * @indent) end
def push_heredoc(heredoc)
-
heredoc
(String
) --
def push_heredoc(heredoc) @heredocs << heredoc end
def root_indent
def root_indent before = @indent @indent = 0 yield @indent = before end
def unindent
- Api: - private
Returns:
-
(self)
-
def unindent @indent -= 1 self end
def write(fragment)
-
(self)
-
Parameters:
-
fragment
(String
) --
def write(fragment) @content << fragment self end
def write_encoding(encoding)
def write_encoding(encoding) write("# -*- encoding: #{encoding} -*-\n") end