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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of IVar.



5726
5727
5728
5729
5730
# File 'lib/syntax_tree/node.rb', line 5726

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

Instance Attribute Details

#comments ⇒ Object (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



5724
5725
5726
# File 'lib/syntax_tree/node.rb', line 5724

def comments
  @comments
end

#value ⇒ Object (readonly)

[String] the name of the instance variable



5721
5722
5723
# File 'lib/syntax_tree/node.rb', line 5721

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



5732
5733
5734
# File 'lib/syntax_tree/node.rb', line 5732

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

#child_nodes ⇒ Object Also known as: deconstruct



5736
5737
5738
# File 'lib/syntax_tree/node.rb', line 5736

def child_nodes
  []
end

#deconstruct_keys(_keys) ⇒ Object



5742
5743
5744
# File 'lib/syntax_tree/node.rb', line 5742

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

#format(q) ⇒ Object



5746
5747
5748
# File 'lib/syntax_tree/node.rb', line 5746

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