class Crodoc::Source
- Crodoc::Source
- Reference
- Object
Overview
Represents a Crystal source file.
Defined in:
crodoc/source.crConstructors
Instance Method Summary
-
#ast
Returns AST nodes constructed by
Crystal::Parser
. -
#code : String
Contents of the source file
-
#fullpath
The full, expanded path to the source file.
-
#lines
Returns the lines of code by splitting the
#code
by on newlines. -
#matches_path?(filepath)
Returns true if filepath matches the source's path, false if it does not.
-
#path : String
Path to the source file
Constructor Detail
def self.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 Method Detail
def ast
#
Returns AST nodes constructed by Crystal::Parser
.
Example
source = Crodoc::Source.new(code, path)
source.ast
def 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"]
def matches_path?(filepath)
#
Returns true if filepath matches the source's path, false if it does not.