Class: Decode::Language::Ruby::Definition
- Inherits:
-
Definition
- Object
- Symbol
- Definition
- Decode::Language::Ruby::Definition
- Defined in:
- lib/decode/language/ruby/definition.rb
Overview
A Ruby-specific definition.
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
The parser syntax tree node.
Attributes inherited from Definition
Attributes inherited from Symbol
#kind, #language, #name, #parent
Instance Method Summary collapse
-
#initialize(kind, name, comments, node, **options) ⇒ Definition
constructor
Initialize the definition from the syntax tree node.
- #multiline? ⇒ Boolean
-
#text ⇒ String
The source code associated with the definition.
Methods inherited from Definition
#container?, #documentation, #long_form, #nested?, #qualified_form, #short_form
Methods inherited from Symbol
#inspect, #key, #lexical_path, #path, #qualified_name
Constructor Details
#initialize(kind, name, comments, node, **options) ⇒ Definition
Initialize the definition from the syntax tree node.
29 30 31 32 33 |
# File 'lib/decode/language/ruby/definition.rb', line 29 def initialize(kind, name, comments, node, **) super(kind, name, comments, **) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
The parser syntax tree node.
36 37 38 |
# File 'lib/decode/language/ruby/definition.rb', line 36 def node @node end |
Instance Method Details
#multiline? ⇒ Boolean
38 39 40 |
# File 'lib/decode/language/ruby/definition.rb', line 38 def multiline? @node.location.line != @node.location.last_line end |
#text ⇒ String
The source code associated with the definition.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/decode/language/ruby/definition.rb', line 44 def text expression = @node.location.expression lines = expression.source.lines if lines.count == 1 return lines.first else indentation = expression.source_line[/\A\s+/] # Remove all the indentation: lines.each{|line| line.sub!(indentation, '')} return lines.join end end |