Class: SyntaxTree::VarField

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

Overview

VarField represents a variable that is being assigned a value. As such, it is always a child of an assignment type node.

variable = value

In the example above, the VarField node represents the variable token.

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: []) ⇒ VarField

Returns a new instance of VarField.



8657
8658
8659
8660
8661
# File 'lib/syntax_tree/node.rb', line 8657

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



8655
8656
8657
# File 'lib/syntax_tree/node.rb', line 8655

def comments
  @comments
end

#valueObject (readonly)

nil | Const | CVar | GVar | Ident | IVar

the target of this node



8652
8653
8654
# File 'lib/syntax_tree/node.rb', line 8652

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8663
8664
8665
# File 'lib/syntax_tree/node.rb', line 8663

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

#child_nodesObject Also known as: deconstruct



8667
8668
8669
# File 'lib/syntax_tree/node.rb', line 8667

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



8673
8674
8675
# File 'lib/syntax_tree/node.rb', line 8673

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

#format(q) ⇒ Object



8677
8678
8679
# File 'lib/syntax_tree/node.rb', line 8677

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