class YARD::Parser::Ruby::Legacy::StatementList

def process_initial_comment(tk)

Returns:
  • (Boolean) - whether or not +tk+ was processed as an initial comment

Parameters:
  • tk (RubyToken::Token) -- the token to process
def process_initial_comment(tk)
  if @statement.empty? && (@comments_last_line || 0) < tk.line_no - 2
    @comments = nil
  end
  return unless tk.class == TkCOMMENT
  case tk.text
  when Parser::SourceParser::SHEBANG_LINE
    if !@last_ns_tk && !@encoding_line
      @shebang_line = tk.text
      return
    end
  when Parser::SourceParser::ENCODING_LINE
    if (@last_ns_tk.class == TkCOMMENT && @last_ns_tk.text == @shebang_line) ||
       !@last_ns_tk
      @encoding_line = tk.text
      return
    end
  end
  return if !@statement.empty? && @comments
  return if @first_line && tk.line_no > @first_line
  if @comments_last_line && @comments_last_line < tk.line_no - 1
    if @comments && @statement.empty?
      @tokens.unshift(tk)
      return @done = true
    end
    @comments = nil
  end
  @comments_line = tk.line_no unless @comments
  # Remove the "#" and up to 1 space before the text
  # Since, of course, the convention is to have "# text"
  # and not "#text", which I deem ugly (you heard it here first)
  @comments ||= []
  if tk.text.start_with?('=begin')
    lines = tk.text.count("\n")
    @comments += tk.text.gsub(/\A=begin.*\r?\n|\r?\n=end.*\r?\n?\Z/, '').split(/\r?\n/)
    @comments_last_line = tk.line_no + lines
  else
    @comments << tk.text.gsub(/^(#+)\s{0,1}/, '')
    @comments_hash_flag = $1 == '##' if @comments_hash_flag.nil?
    @comments_last_line = tk.line_no
  end
  @comments.pop if @comments.size == 1 && @comments.first =~ /^\s*$/
  true
end