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.
2750 2751 2752 2753 2754 2755 2756 |
# File 'lib/syntax_tree/node.rb', line 2750 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
2748 2749 2750 |
# File 'lib/syntax_tree/node.rb', line 2748 def comments @comments end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
2742 2743 2744 |
# File 'lib/syntax_tree/node.rb', line 2742 def operator @operator end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern on the right-hand side of the expression
2745 2746 2747 |
# File 'lib/syntax_tree/node.rb', line 2745 def pattern @pattern end |
#value ⇒ Object (readonly)
- untyped
-
the left-hand expression
2738 2739 2740 |
# File 'lib/syntax_tree/node.rb', line 2738 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
2758 2759 2760 |
# File 'lib/syntax_tree/node.rb', line 2758 def accept(visitor) visitor.visit_rassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2762 2763 2764 |
# File 'lib/syntax_tree/node.rb', line 2762 def child_nodes [value, operator, pattern] end |
#deconstruct_keys(_keys) ⇒ Object
2768 2769 2770 2771 2772 2773 2774 2775 2776 |
# File 'lib/syntax_tree/node.rb', line 2768 def deconstruct_keys(_keys) { value: value, operator: operator, pattern: pattern, location: location, comments: comments } end |
#format(q) ⇒ Object
2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 |
# File 'lib/syntax_tree/node.rb', line 2778 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 |