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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign

Returns a new instance of RAssign.



2747
2748
2749
2750
2751
2752
2753
# File 'lib/syntax_tree/node.rb', line 2747

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

Instance Attribute Details

#comments ⇒ Object (readonly)

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



2745
2746
2747
# File 'lib/syntax_tree/node.rb', line 2745

def comments
  @comments
end

#operator ⇒ Object (readonly)

[Kw | Op] the operator being used to match against the pattern, which is either => or in



2739
2740
2741
# File 'lib/syntax_tree/node.rb', line 2739

def operator
  @operator
end

#pattern ⇒ Object (readonly)

[untyped] the pattern on the right-hand side of the expression



2742
2743
2744
# File 'lib/syntax_tree/node.rb', line 2742

def pattern
  @pattern
end

#value ⇒ Object (readonly)

[untyped] the left-hand expression



2735
2736
2737
# File 'lib/syntax_tree/node.rb', line 2735

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



2755
2756
2757
# File 'lib/syntax_tree/node.rb', line 2755

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

#child_nodes ⇒ Object Also known as: deconstruct



2759
2760
2761
# File 'lib/syntax_tree/node.rb', line 2759

def child_nodes
  [value, operator, pattern]
end

#deconstruct_keys(_keys) ⇒ Object



2765
2766
2767
2768
2769
2770
2771
2772
2773
# File 'lib/syntax_tree/node.rb', line 2765

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

#format(q) ⇒ Object



2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
# File 'lib/syntax_tree/node.rb', line 2775

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