Class: SyntaxTree::Rescue
Overview
Rescue represents the use of the rescue keyword inside of a BodyStmt node.
begin
rescue
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil | Rescue
-
the optional next clause in the chain.
-
#exception ⇒ Object
readonly
- RescueEx
-
the exceptions being rescued.
-
#keyword ⇒ Object
readonly
- Kw
-
the rescue keyword.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to evaluate when an error is rescued.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #bind_end(end_char, end_column) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, exception:, statements:, consequent:, location:, comments: []) ⇒ Rescue
constructor
A new instance of Rescue.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, exception:, statements:, consequent:, location:, comments: []) ⇒ Rescue
Returns a new instance of Rescue.
7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 |
# File 'lib/syntax_tree/node.rb', line 7657 def initialize( keyword:, exception:, statements:, consequent:, location:, comments: [] ) @keyword = keyword @exception = exception @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7655 7656 7657 |
# File 'lib/syntax_tree/node.rb', line 7655 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Rescue
-
the optional next clause in the chain
7652 7653 7654 |
# File 'lib/syntax_tree/node.rb', line 7652 def consequent @consequent end |
#exception ⇒ Object (readonly)
- RescueEx
-
the exceptions being rescued
7646 7647 7648 |
# File 'lib/syntax_tree/node.rb', line 7646 def exception @exception end |
#keyword ⇒ Object (readonly)
- Kw
-
the rescue keyword
7643 7644 7645 |
# File 'lib/syntax_tree/node.rb', line 7643 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to evaluate when an error is rescued
7649 7650 7651 |
# File 'lib/syntax_tree/node.rb', line 7649 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
7695 7696 7697 |
# File 'lib/syntax_tree/node.rb', line 7695 def accept(visitor) visitor.visit_rescue(self) end |
#bind_end(end_char, end_column) ⇒ Object
7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 |
# File 'lib/syntax_tree/node.rb', line 7673 def bind_end(end_char, end_column) @location = Location.new( start_line: location.start_line, start_char: location.start_char, start_column: location.start_column, end_line: location.end_line, end_char: end_char, end_column: end_column ) if consequent consequent.bind_end(end_char, end_column) statements.bind_end( consequent.location.start_char, consequent.location.start_column ) else statements.bind_end(end_char, end_column) end end |
#child_nodes ⇒ Object Also known as: deconstruct
7699 7700 7701 |
# File 'lib/syntax_tree/node.rb', line 7699 def child_nodes [keyword, exception, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 |
# File 'lib/syntax_tree/node.rb', line 7705 def deconstruct_keys(_keys) { keyword: keyword, exception: exception, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 |
# File 'lib/syntax_tree/node.rb', line 7716 def format(q) q.group do q.format(keyword) if exception q.nest(keyword.value.length + 1) { q.format(exception) } else q.text(" StandardError") end unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end if consequent q.breakable(force: true) q.format(consequent) end end end |