Class: Decode::Language::Ruby::Definition
- Inherits:
-
Definition
- Object
- 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
Returns the value of attribute node.
- #The parser syntax tree node.(parsersyntaxtreenode.) ⇒ Object readonly
-
#visibility ⇒ Object
Returns the value of attribute visibility.
Attributes inherited from Definition
#comments, #language, #name, #parent
Instance Method Summary collapse
-
#initialize(node, *arguments, visibility: nil, **options) ⇒ Definition
constructor
Initialize the definition from the syntax tree node.
- #location ⇒ Object
- #multiline? ⇒ Boolean
- #nested_name ⇒ Object
- #public? ⇒ Boolean
-
#text ⇒ Object
The source code associated with the definition.
- #The visibility of the definition.=(visibilityofthedefinition. = (value)) ⇒ Object
Methods inherited from Definition
#container?, #convert, #documentation, #inspect, #long_form, #nested?, #path, #path_name, #qualified_form, #qualified_name, #short_form, #start_with?
Constructor Details
#initialize(node, *arguments, visibility: nil, **options) ⇒ Definition
Initialize the definition from the syntax tree node.
14 15 16 17 18 19 |
# File 'lib/decode/language/ruby/definition.rb', line 14 def initialize(node, *arguments, visibility: nil, **) super(*arguments, **) @node = node @visibility = visibility end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
26 27 28 |
# File 'lib/decode/language/ruby/definition.rb', line 26 def node @node end |
#The parser syntax tree node.(parsersyntaxtreenode.) ⇒ Object (readonly)
26 |
# File 'lib/decode/language/ruby/definition.rb', line 26 attr :node |
#visibility ⇒ Object
Returns the value of attribute visibility.
29 30 31 |
# File 'lib/decode/language/ruby/definition.rb', line 29 def visibility @visibility end |
Instance Method Details
#location ⇒ Object
56 57 58 59 60 |
# File 'lib/decode/language/ruby/definition.rb', line 56 def location expression = @node.location.expression Location.new(expression.source_buffer.name, expression.line) end |
#multiline? ⇒ Boolean
35 36 37 |
# File 'lib/decode/language/ruby/definition.rb', line 35 def multiline? @node.location.line != @node.location.last_line end |
#nested_name ⇒ Object
21 22 23 |
# File 'lib/decode/language/ruby/definition.rb', line 21 def nested_name "\##{@name}" end |
#public? ⇒ Boolean
31 32 33 |
# File 'lib/decode/language/ruby/definition.rb', line 31 def public? @visibility == :public end |
#text ⇒ Object
The source code associated with the definition.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/decode/language/ruby/definition.rb', line 41 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 |
#The visibility of the definition.=(visibilityofthedefinition. = (value)) ⇒ Object
29 |
# File 'lib/decode/language/ruby/definition.rb', line 29 attr_accessor :visibility |