class Unparser::Buffer

Buffer used to emit into

def append(string)

Other tags:
    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)

Other tags:
    Api: - private

Returns:
  • (self) -

Parameters:
  • string (String) --
def append_without_prefix(string)
  write(string)
end

def content

Other tags:
    Api: - private

Returns:
  • (String) -
def content
  @content.dup.freeze
end

def ensure_nl

def ensure_nl
  nl unless fresh_line?
end

def final_newline

Write 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?

Other tags:
    Api: - private

Returns:
  • (Boolean) -
def fresh_line?
  @content.empty? || @content[-1].eql?(NL)
end

def indent

Other tags:
    Api: - private

Returns:
  • (self) -
def indent
  @indent += 1
  self
end

def initialize

Other tags:
    Api: - private

Returns:
  • (undefined) -
def initialize
  @content  = +''
  @heredocs = []
  @indent   = 0
  @no_nl    = true
end

def nl

Other tags:
    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)

Parameters:
  • 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

Other tags:
    Api: - private

Returns:
  • (self) -
def unindent
  @indent -= 1
  self
end

def write(fragment)

Returns:
  • (self) -

Parameters:
  • fragment (String) --
def write(fragment)
  @content << fragment
  self
end

def write_encoding(encoding)

def write_encoding(encoding)
  write("# -*- encoding: #{encoding} -*-\n")
end