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
Constructor Details
#initialize(keyword:, exception:, statements:, consequent:, location:, comments: []) ⇒ Rescue
6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 |
# File 'lib/syntax_tree/node.rb', line 6896 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
6894 6895 6896 |
# File 'lib/syntax_tree/node.rb', line 6894 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil | Rescue
-
the optional next clause in the chain
6891 6892 6893 |
# File 'lib/syntax_tree/node.rb', line 6891 def consequent @consequent end |
#exception ⇒ Object (readonly)
- RescueEx
-
the exceptions being rescued
6885 6886 6887 |
# File 'lib/syntax_tree/node.rb', line 6885 def exception @exception end |
#keyword ⇒ Object (readonly)
- Kw
-
the rescue keyword
6882 6883 6884 |
# File 'lib/syntax_tree/node.rb', line 6882 def keyword @keyword end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to evaluate when an error is rescued
6888 6889 6890 |
# File 'lib/syntax_tree/node.rb', line 6888 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
6931 6932 6933 |
# File 'lib/syntax_tree/node.rb', line 6931 def accept(visitor) visitor.visit_rescue(self) end |
#bind_end(end_char, end_column) ⇒ Object
6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 |
# File 'lib/syntax_tree/node.rb', line 6912 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
6935 6936 6937 |
# File 'lib/syntax_tree/node.rb', line 6935 def child_nodes [keyword, exception, statements, consequent] end |
#deconstruct_keys(keys) ⇒ Object
6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 |
# File 'lib/syntax_tree/node.rb', line 6941 def deconstruct_keys(keys) { keyword: keyword, exception: exception, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 |
# File 'lib/syntax_tree/node.rb', line 6952 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 |