github-flavored-markdown icon indicating copy to clipboard operation
github-flavored-markdown copied to clipboard

YARD::Docstring#summary appends "." on each use

Open dkubb opened this issue 14 years ago • 0 comments

The #summary method prepends a period each time is is used on a non-blank summary. When used more than once on a docstring this causes several trailing periods to appear at the end of the summary.

The solution would be to check the last character and only append if it is not a period. An alternative (and IMHO better) solution would be to perform the appending one time, and memoize the results, so something like:

def summary
  return @summary if defined?(@summary)
  summary = split(/\.|\r?\n\r?\n/).first || ''
  unless summmary.empty? || summary[-1, 1] == '.'
    summary += '.'
  end
  @summary = summary.freeze
end

dkubb avatar Jul 23 '09 05:07 dkubb