class

Crodoc::Source

Inherits Reference / Object

Represents a Crystal source file.

Constructors

new(code : String, path : String)

Creates a new source using code and path.

Example:

path = "./src/source.cr"
Crodoc::Source.new(File.read(path), path)
Source

Instance methods

ast

Returns AST nodes constructed by Crystal::Parser.

Example

source = Crodoc::Source.new(code, path)
source.ast
Source
code

Contents of the source file

Source
fullpath

The full, expanded path to the source file.

Source
lines

Returns the lines of code by splitting the code by on newlines. Lines are cached and lazily loaded.

Example:

source = Crodoc::Source.new("a = 1\nb = 2", "")
source.lines # => ["a = 1", "b = 2"]
Source
matches_path?(filepath)

Returns true if filepath matches the source's path, false if it does not.

Source
path

Path to the source file

Source