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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, operator: nil, pattern: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, operator:, pattern:, location:) ⇒ RAssign
constructor
A new instance of RAssign.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, operator:, pattern:, location:) ⇒ RAssign
Returns a new instance of RAssign.
3138 3139 3140 3141 3142 3143 3144 |
# File 'lib/syntax_tree/node.rb', line 3138 def initialize(value:, operator:, pattern:, location:) @value = value @operator = operator @pattern = pattern @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3136 3137 3138 |
# File 'lib/syntax_tree/node.rb', line 3136 def comments @comments end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
3130 3131 3132 |
# File 'lib/syntax_tree/node.rb', line 3130 def operator @operator end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern on the right-hand side of the expression
3133 3134 3135 |
# File 'lib/syntax_tree/node.rb', line 3133 def pattern @pattern end |
#value ⇒ Object (readonly)
- untyped
-
the left-hand expression
3126 3127 3128 |
# File 'lib/syntax_tree/node.rb', line 3126 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3200 3201 3202 3203 |
# File 'lib/syntax_tree/node.rb', line 3200 def ===(other) other.is_a?(RAssign) && value === other.value && operator === other.operator && pattern === other.pattern end |
#accept(visitor) ⇒ Object
3146 3147 3148 |
# File 'lib/syntax_tree/node.rb', line 3146 def accept(visitor) visitor.visit_rassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3150 3151 3152 |
# File 'lib/syntax_tree/node.rb', line 3150 def child_nodes [value, operator, pattern] end |
#copy(value: nil, operator: nil, pattern: nil, location: nil) ⇒ Object
3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 |
# File 'lib/syntax_tree/node.rb', line 3154 def copy(value: nil, operator: nil, pattern: nil, location: nil) node = RAssign.new( value: value || self.value, operator: operator || self.operator, pattern: pattern || self.pattern, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
3169 3170 3171 3172 3173 3174 3175 3176 3177 |
# File 'lib/syntax_tree/node.rb', line 3169 def deconstruct_keys(_keys) { value: value, operator: operator, pattern: pattern, location: location, comments: comments } end |
#format(q) ⇒ Object
3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 |
# File 'lib/syntax_tree/node.rb', line 3179 def format(q) q.group do q.format(value) q.text(" ") q.format(operator) case pattern when AryPtn, FndPtn, HshPtn q.text(" ") q.format(pattern) else q.group do q.indent do q.breakable_space q.format(pattern) end end end end end |