class RubyNext::Language::Rewriters::SquigglyHeredoc

Constants

MIN_SUPPORTED_VERSION
NAME
SYNTAX_PROBE

Public Instance Methods

on_dstr(node)
Alias for: on_str
on_str(node) click to toggle source
Calls superclass method
# File lib/ruby-next/language/rewriters/squiggly_heredoc.rb, line 11
def on_str(node)
  node = super(node) if defined?(super_method)
  return node unless node.loc.respond_to?(:heredoc_body) && node.loc.expression.source.include?("<<~")

  context.track! self

  replace(node.loc.expression, node.loc.expression.source.tr("~", "-"))

  heredoc_loc = node.loc.heredoc_body.join(node.loc.heredoc_end)
  heredoc_source, heredoc_end = heredoc_loc.source.split(/\n([^\n]+)\z/)

  indent = heredoc_source.lines.map { |line| line.match(/^\s*/)[0].size }.min

  new_source = heredoc_source.gsub!(%r{^\s{#{indent}}}, "")

  replace(heredoc_loc, [new_source, heredoc_end].join("\n"))

  node
end
Also aliased as: on_dstr, on_xstr
on_xstr(node)
Alias for: on_str