Class: SyntaxTree::RAssign
Overview
RAssign represents a single-line pattern match.
value in pattern
value => pattern
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#operator ⇒ Object
readonly
- Kw | Op
-
the operator being used to match against the pattern, which is either => or in.
-
#pattern ⇒ Object
readonly
- untyped
-
the pattern on the right-hand side of the expression.
-
#value ⇒ Object
readonly
- untyped
-
the left-hand expression.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign
constructor
A new instance of RAssign.
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.
2739 2740 2741 2742 2743 2744 2745 |
# File 'lib/syntax_tree/node.rb', line 2739 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
2737 2738 2739 |
# File 'lib/syntax_tree/node.rb', line 2737 def comments @comments end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
2731 2732 2733 |
# File 'lib/syntax_tree/node.rb', line 2731 def operator @operator end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern on the right-hand side of the expression
2734 2735 2736 |
# File 'lib/syntax_tree/node.rb', line 2734 def pattern @pattern end |
#value ⇒ Object (readonly)
- untyped
-
the left-hand expression
2727 2728 2729 |
# File 'lib/syntax_tree/node.rb', line 2727 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
2747 2748 2749 |
# File 'lib/syntax_tree/node.rb', line 2747 def accept(visitor) visitor.visit_rassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2751 2752 2753 |
# File 'lib/syntax_tree/node.rb', line 2751 def child_nodes [value, operator, pattern] end |
#deconstruct_keys(_keys) ⇒ Object
2757 2758 2759 2760 2761 2762 2763 2764 2765 |
# File 'lib/syntax_tree/node.rb', line 2757 def deconstruct_keys(_keys) { value: value, operator: operator, pattern: pattern, location: location, comments: comments } end |
#format(q) ⇒ Object
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 |
# File 'lib/syntax_tree/node.rb', line 2767 def format(q) q.group do q.format(value) q.text(" ") q.format(operator) case pattern in AryPtn | FndPtn | HshPtn q.text(" ") q.format(pattern) else q.group do q.indent do q.breakable q.format(pattern) end end end end end |