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

#construct_keys, #pretty_print, #to_json

Constructor Details

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



9508
9509
9510
9511
9512
# File 'lib/syntax_tree/node.rb', line 9508

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



9506
9507
9508
# File 'lib/syntax_tree/node.rb', line 9506

def comments
  @comments
end

#valueObject (readonly)

nil | Const | CVar | GVar | Ident | IVar

the target of this node



9503
9504
9505
# File 'lib/syntax_tree/node.rb', line 9503

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9514
9515
9516
# File 'lib/syntax_tree/node.rb', line 9514

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

#child_nodesObject Also known as: deconstruct



9518
9519
9520
# File 'lib/syntax_tree/node.rb', line 9518

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



9524
9525
9526
# File 'lib/syntax_tree/node.rb', line 9524

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

#format(q) ⇒ Object



9528
9529
9530
9531
9532
9533
9534
# File 'lib/syntax_tree/node.rb', line 9528

def format(q)
  if value == :nil
    q.text("nil")
  elsif value
    q.format(value)
  end
end