Class: SyntaxTree::IVar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

IVar represents an instance variable literal.

@variable

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ IVar

Returns a new instance of IVar.



5084
5085
5086
5087
5088
# File 'lib/syntax_tree/node.rb', line 5084

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5082
5083
5084
# File 'lib/syntax_tree/node.rb', line 5082

def comments
  @comments
end

#valueObject (readonly)

String

the name of the instance variable



5079
5080
5081
# File 'lib/syntax_tree/node.rb', line 5079

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



5090
5091
5092
# File 'lib/syntax_tree/node.rb', line 5090

def accept(visitor)
  visitor.visit_ivar(self)
end

#child_nodesObject Also known as: deconstruct



5094
5095
5096
# File 'lib/syntax_tree/node.rb', line 5094

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



5100
5101
5102
# File 'lib/syntax_tree/node.rb', line 5100

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



5104
5105
5106
# File 'lib/syntax_tree/node.rb', line 5104

def format(q)
  q.text(value)
end