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

Returns a new instance of VarField.



9441
9442
9443
9444
9445
# File 'lib/syntax_tree/node.rb', line 9441

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



9439
9440
9441
# File 'lib/syntax_tree/node.rb', line 9439

def comments
  @comments
end

#value ⇒ Object (readonly)

[nil | Const | CVar | GVar | Ident | IVar] the target of this node



9436
9437
9438
# File 'lib/syntax_tree/node.rb', line 9436

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9447
9448
9449
# File 'lib/syntax_tree/node.rb', line 9447

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

#child_nodes ⇒ Object Also known as: deconstruct



9451
9452
9453
# File 'lib/syntax_tree/node.rb', line 9451

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



9457
9458
9459
# File 'lib/syntax_tree/node.rb', line 9457

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

#format(q) ⇒ Object



9461
9462
9463
9464
9465
9466
9467
# File 'lib/syntax_tree/node.rb', line 9461

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