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.
7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 |
# File 'lib/syntax_tree/node.rb', line 7699 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
7697 7698 7699 |
# File 'lib/syntax_tree/node.rb', line 7697 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Rescue
-
the optional next clause in the chain
7694 7695 7696 |
# File 'lib/syntax_tree/node.rb', line 7694 def consequent @consequent end |
#exception ⇒ Object (readonly)
- RescueEx
-
the exceptions being rescued
7688 7689 7690 |
# File 'lib/syntax_tree/node.rb', line 7688 def exception @exception end |
#keyword ⇒ Object (readonly)
- Kw
-
the rescue keyword
7685 7686 7687 |
# File 'lib/syntax_tree/node.rb', line 7685 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to evaluate when an error is rescued
7691 7692 7693 |
# File 'lib/syntax_tree/node.rb', line 7691 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
7737 7738 7739 |
# File 'lib/syntax_tree/node.rb', line 7737 def accept(visitor) visitor.visit_rescue(self) end |
#bind_end(end_char, end_column) ⇒ Object
7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 |
# File 'lib/syntax_tree/node.rb', line 7715 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
7741 7742 7743 |
# File 'lib/syntax_tree/node.rb', line 7741 def child_nodes [keyword, exception, statements, consequent] end |
#deconstruct_keys(_keys) ⇒ Object
7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 |
# File 'lib/syntax_tree/node.rb', line 7747 def deconstruct_keys(_keys) { keyword: keyword, exception: exception, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 |
# File 'lib/syntax_tree/node.rb', line 7758 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 |