class Definition
A Ruby-specific definition.
Definitions
def initialize(node, *arguments, **options)
Initialize the definition from the syntax tree node.
Implementation
def initialize(node, *arguments, **options)
super(*arguments, **options)
@node = node
end
attr :node
The parser syntax tree node.
def text
The source code associated with the definition.
Signature
-
returns
String
Implementation
def text
expression = @node.location.expression
lines = expression.source.lines
if lines.count == 1
return lines.first
else
if indentation = expression.source_line[/\A\s+/]
# Remove all the indentation:
lines.each{|line| line.sub!(indentation, '')}
end
return lines.join
end
end