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)
Instance methods
ast
Returns AST nodes constructed by Crystal::Parser.
Example
source = Crodoc::Source.new(code, path)
source.ast
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"]
matches_path?(filepath)
Returns true if filepath matches the source's path, false if it does not.