Module MethodSource::CodeHelpers
In: lib/method_source/code_helpers.rb

Methods

Classes and Modules

Module MethodSource::CodeHelpers::IncompleteExpression

Public Instance methods

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

This is useful to get module or method documentation.

@param [Array<String>, File, String] file The file to parse, either as a File or as

                                           a String or an Array of lines.

@param [Fixnum] line_number The line number at which to look.

                            NOTE: The first line in a file is line 1!

@return [String] The comment

Determine if a string of code is a complete Ruby expression. @param [String] code The code to validate. @return [Boolean] Whether or not the code is a complete Ruby expression. @raise [SyntaxError] Any SyntaxError that does not represent incompleteness. @example

  complete_expression?("class Hello") #=> false
  complete_expression?("class Hello; end") #=> true
  complete_expression?("class 123") #=> SyntaxError: unexpected tINTEGER

Retrieve the first expression starting on the given line of the given file.

This is useful to get module or method source code.

@param [Array<String>, File, String] file The file to parse, either as a File or as @param [Fixnum] line_number The line number at which to look.

                            NOTE: The first line in a file is
                          line 1!

@param [Hash] options The optional configuration parameters. @option options [Boolean] :strict If set to true, then only completely

  valid expressions are returned. Otherwise heuristics are used to extract
  expressions that may have been valid inside an eval.

@option options [Fixnum] :consume A number of lines to automatically

  consume (add to the expression buffer) without checking for validity.

@return [String] The first complete expression @raise [SyntaxError] If the first complete expression can‘t be identified

[Validate]