Class: SyntaxTree::RAssign

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

Overview

RAssign represents a single-line pattern match.

value in pattern
value => pattern

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:, operator:, pattern:, location:, comments: []) ⇒ RAssign

Returns a new instance of RAssign.



2668
2669
2670
2671
2672
2673
2674
# File 'lib/syntax_tree/node.rb', line 2668

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2666
2667
2668
# File 'lib/syntax_tree/node.rb', line 2666

def comments
  @comments
end

#operatorObject (readonly)

Kw | Op

the operator being used to match against the pattern, which is

either => or in



2660
2661
2662
# File 'lib/syntax_tree/node.rb', line 2660

def operator
  @operator
end

#patternObject (readonly)

untyped

the pattern on the right-hand side of the expression



2663
2664
2665
# File 'lib/syntax_tree/node.rb', line 2663

def pattern
  @pattern
end

#valueObject (readonly)

untyped

the left-hand expression



2656
2657
2658
# File 'lib/syntax_tree/node.rb', line 2656

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



2676
2677
2678
# File 'lib/syntax_tree/node.rb', line 2676

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

#child_nodesObject Also known as: deconstruct



2680
2681
2682
# File 'lib/syntax_tree/node.rb', line 2680

def child_nodes
  [value, operator, pattern]
end

#deconstruct_keys(keys) ⇒ Object



2686
2687
2688
2689
2690
2691
2692
2693
2694
# File 'lib/syntax_tree/node.rb', line 2686

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

#format(q) ⇒ Object



2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
# File 'lib/syntax_tree/node.rb', line 2696

def format(q)
  q.group do
    q.format(value)
    q.text(" ")
    q.format(operator)
    q.group do
      q.indent do
        q.breakable
        q.format(pattern)
      end
    end
  end
end