Class: SyntaxTree::RescueEx
Overview
RescueEx represents the list of exceptions being rescued in a rescue clause.
begin
rescue Exception => exception
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#exceptions ⇒ Object
readonly
- nil | Node
-
the list of exceptions being rescued.
-
#variable ⇒ Object
readonly
- nil | Field | VarField
-
the expression being used to capture the raised exception.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(exceptions: nil, variable: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(exceptions:, variable:, location:) ⇒ RescueEx
constructor
A new instance of RescueEx.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(exceptions:, variable:, location:) ⇒ RescueEx
Returns a new instance of RescueEx.
9359 9360 9361 9362 9363 9364 |
# File 'lib/syntax_tree/node.rb', line 9359 def initialize(exceptions:, variable:, location:) @exceptions = exceptions @variable = variable @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9357 9358 9359 |
# File 'lib/syntax_tree/node.rb', line 9357 def comments @comments end |
#exceptions ⇒ Object (readonly)
- nil | Node
-
the list of exceptions being rescued
9350 9351 9352 |
# File 'lib/syntax_tree/node.rb', line 9350 def exceptions @exceptions end |
#variable ⇒ Object (readonly)
- nil | Field | VarField
-
the expression being used to capture the raised
exception
9354 9355 9356 |
# File 'lib/syntax_tree/node.rb', line 9354 def variable @variable end |
Instance Method Details
#===(other) ⇒ Object
9411 9412 9413 9414 |
# File 'lib/syntax_tree/node.rb', line 9411 def ===(other) other.is_a?(RescueEx) && exceptions === other.exceptions && variable === other.variable end |
#accept(visitor) ⇒ Object
9366 9367 9368 |
# File 'lib/syntax_tree/node.rb', line 9366 def accept(visitor) visitor.visit_rescue_ex(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9370 9371 9372 |
# File 'lib/syntax_tree/node.rb', line 9370 def child_nodes [*exceptions, variable] end |
#copy(exceptions: nil, variable: nil, location: nil) ⇒ Object
9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 |
# File 'lib/syntax_tree/node.rb', line 9374 def copy(exceptions: nil, variable: nil, location: nil) node = RescueEx.new( exceptions: exceptions || self.exceptions, variable: variable || self.variable, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
9388 9389 9390 9391 9392 9393 9394 9395 |
# File 'lib/syntax_tree/node.rb', line 9388 def deconstruct_keys(_keys) { exceptions: exceptions, variable: variable, location: location, comments: comments } end |
#format(q) ⇒ Object
9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 |
# File 'lib/syntax_tree/node.rb', line 9397 def format(q) q.group do if exceptions q.text(" ") q.format(exceptions) end if variable q.text(" => ") q.format(variable) end end end |