class Definition
A Ruby-specific definition.
Definitions
def initialize(node, *arguments, visibility: nil, **options)
Initialize the definition from the syntax tree node.
Implementation
def initialize(node, *arguments, visibility: nil, **options)
super(*arguments, **options)
@node = node
@visibility = visibility
end
attr :node
Signature
-
attribute
Parser::AST::Node
The parser syntax tree node.
attr_accessor :visibility
Signature
-
attribute
Symbol
The visibility of the definition.
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