Class: SyntaxTree::RescueMod
Overview
RescueMod represents the use of the modifier form of a rescue clause.
expression rescue value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#statement ⇒ Object
readonly
- Node
-
the expression to execute.
-
#value ⇒ Object
readonly
- Node
-
the value to use if the executed expression raises an error.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(statement: nil, value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, value:, location:) ⇒ RescueMod
constructor
A new instance of RescueMod.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(statement:, value:, location:) ⇒ RescueMod
Returns a new instance of RescueMod.
9556 9557 9558 9559 9560 9561 |
# File 'lib/syntax_tree/node.rb', line 9556 def initialize(statement:, value:, location:) @statement = statement @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9554 9555 9556 |
# File 'lib/syntax_tree/node.rb', line 9554 def comments @comments end |
#statement ⇒ Object (readonly)
- Node
-
the expression to execute
9548 9549 9550 |
# File 'lib/syntax_tree/node.rb', line 9548 def statement @statement end |
#value ⇒ Object (readonly)
- Node
-
the value to use if the executed expression raises an error
9551 9552 9553 |
# File 'lib/syntax_tree/node.rb', line 9551 def value @value end |
Instance Method Details
#===(other) ⇒ Object
9612 9613 9614 9615 |
# File 'lib/syntax_tree/node.rb', line 9612 def ===(other) other.is_a?(RescueMod) && statement === other.statement && value === other.value end |
#accept(visitor) ⇒ Object
9563 9564 9565 |
# File 'lib/syntax_tree/node.rb', line 9563 def accept(visitor) visitor.visit_rescue_mod(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9567 9568 9569 |
# File 'lib/syntax_tree/node.rb', line 9567 def child_nodes [statement, value] end |
#copy(statement: nil, value: nil, location: nil) ⇒ Object
9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 |
# File 'lib/syntax_tree/node.rb', line 9571 def copy(statement: nil, value: nil, location: nil) node = RescueMod.new( statement: statement || self.statement, value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
9585 9586 9587 9588 9589 9590 9591 9592 |
# File 'lib/syntax_tree/node.rb', line 9585 def deconstruct_keys(_keys) { statement: statement, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 |
# File 'lib/syntax_tree/node.rb', line 9594 def format(q) q.text("begin") q.group do q.indent do q.breakable_force q.format(statement) end q.breakable_force q.text("rescue StandardError") q.indent do q.breakable_force q.format(value) end q.breakable_force end q.text("end") end |