Method: MethodSource::CodeHelpers#comment_describing

Defined in:
lib/method_source/code_helpers.rb

#comment_describing(file, line_number) ⇒ String

Retrieve the comment describing the expression on the given line of the given file.

This is useful to get module or method documentation.

Parameters:

  • file (Array<String>, File, String)

    The file to parse, either as a File or as a String or an Array of lines.

  • line_number (Integer)

    The line number at which to look. NOTE: The first line in a file is line 1!

Returns:

  • (String)

    The comment



52
53
54
55
56
# File 'lib/method_source/code_helpers.rb', line 52

def comment_describing(file, line_number)
  lines = file.is_a?(Array) ? file : file.each_line.to_a

  extract_last_comment(lines[0..(line_number - 2)])
end