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.
9557 9558 9559 9560 9561 9562 |
# File 'lib/syntax_tree/node.rb', line 9557 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
9555 9556 9557 |
# File 'lib/syntax_tree/node.rb', line 9555 def comments @comments end |
#statement ⇒ Object (readonly)
- Node
-
the expression to execute
9549 9550 9551 |
# File 'lib/syntax_tree/node.rb', line 9549 def statement @statement end |
#value ⇒ Object (readonly)
- Node
-
the value to use if the executed expression raises an error
9552 9553 9554 |
# File 'lib/syntax_tree/node.rb', line 9552 def value @value end |
Instance Method Details
#===(other) ⇒ Object
9613 9614 9615 9616 |
# File 'lib/syntax_tree/node.rb', line 9613 def ===(other) other.is_a?(RescueMod) && statement === other.statement && value === other.value end |
#accept(visitor) ⇒ Object
9564 9565 9566 |
# File 'lib/syntax_tree/node.rb', line 9564 def accept(visitor) visitor.visit_rescue_mod(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9568 9569 9570 |
# File 'lib/syntax_tree/node.rb', line 9568 def child_nodes [statement, value] end |
#copy(statement: nil, value: nil, location: nil) ⇒ Object
9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 |
# File 'lib/syntax_tree/node.rb', line 9572 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
9586 9587 9588 9589 9590 9591 9592 9593 |
# File 'lib/syntax_tree/node.rb', line 9586 def deconstruct_keys(_keys) { statement: statement, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 |
# File 'lib/syntax_tree/node.rb', line 9595 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 |