Class: YARP::RescueNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::RescueNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a rescue statement.
begin
rescue Foo, *splat, Bar => ex
^^^^^^
foo
end
‘Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `exception` field.
Instance Attribute Summary collapse
-
#consequent ⇒ Object
readonly
attr_reader consequent: RescueNode?.
-
#exceptions ⇒ Object
readonly
attr_reader exceptions: Array.
-
#keyword_loc ⇒ Object
readonly
attr_reader keyword_loc: Location.
-
#operator_loc ⇒ Object
readonly
attr_reader operator_loc: Location?.
-
#reference ⇒ Object
readonly
attr_reader reference: Node?.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> RescueNode.
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) ⇒ RescueNode
constructor
def initialize: (keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: Node?, statements: StatementsNode?, consequent: RescueNode?, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#keyword ⇒ Object
def keyword: () -> String.
-
#operator ⇒ Object
def operator: () -> String?.
Constructor Details
#initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) ⇒ RescueNode
def initialize: (keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: Node?, statements: StatementsNode?, consequent: RescueNode?, location: Location) -> void
8861 8862 8863 8864 8865 8866 8867 8868 8869 |
# File 'lib/yarp/node.rb', line 8861 def initialize(keyword_loc, exceptions, operator_loc, reference, statements, consequent, location) @keyword_loc = keyword_loc @exceptions = exceptions @operator_loc = operator_loc @reference = reference @statements = statements @consequent = consequent @location = location end |
Instance Attribute Details
#consequent ⇒ Object (readonly)
attr_reader consequent: RescueNode?
8858 8859 8860 |
# File 'lib/yarp/node.rb', line 8858 def consequent @consequent end |
#exceptions ⇒ Object (readonly)
attr_reader exceptions: Array
8846 8847 8848 |
# File 'lib/yarp/node.rb', line 8846 def exceptions @exceptions end |
#keyword_loc ⇒ Object (readonly)
attr_reader keyword_loc: Location
8843 8844 8845 |
# File 'lib/yarp/node.rb', line 8843 def keyword_loc @keyword_loc end |
#operator_loc ⇒ Object (readonly)
attr_reader operator_loc: Location?
8849 8850 8851 |
# File 'lib/yarp/node.rb', line 8849 def operator_loc @operator_loc end |
#reference ⇒ Object (readonly)
attr_reader reference: Node?
8852 8853 8854 |
# File 'lib/yarp/node.rb', line 8852 def reference @reference end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
8855 8856 8857 |
# File 'lib/yarp/node.rb', line 8855 def statements @statements end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
8872 8873 8874 |
# File 'lib/yarp/node.rb', line 8872 def accept(visitor) visitor.visit_rescue_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
8877 8878 8879 |
# File 'lib/yarp/node.rb', line 8877 def child_nodes [*exceptions, reference, statements, consequent] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
8882 8883 8884 |
# File 'lib/yarp/node.rb', line 8882 def comment_targets [keyword_loc, *exceptions, *operator_loc, *reference, *statements, *consequent] end |
#copy(**params) ⇒ Object
def copy: (**params) -> RescueNode
8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 |
# File 'lib/yarp/node.rb', line 8887 def copy(**params) RescueNode.new( params.fetch(:keyword_loc) { keyword_loc }, params.fetch(:exceptions) { exceptions }, params.fetch(:operator_loc) { operator_loc }, params.fetch(:reference) { reference }, params.fetch(:statements) { statements }, params.fetch(:consequent) { consequent }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
8903 8904 8905 |
# File 'lib/yarp/node.rb', line 8903 def deconstruct_keys(keys) { keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, statements: statements, consequent: consequent, location: location } end |
#inspect(inspector = NodeInspector.new) ⇒ Object
8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 |
# File 'lib/yarp/node.rb', line 8917 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── keyword_loc: #{inspector.location(keyword_loc)}\n" inspector << "├── exceptions: #{inspector.list("#{inspector.prefix}│ ", exceptions)}" inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n" if (reference = self.reference).nil? inspector << "├── reference: ∅\n" else inspector << "├── reference:\n" inspector << reference.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end if (statements = self.statements).nil? inspector << "├── statements: ∅\n" else inspector << "├── statements:\n" inspector << statements.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end if (consequent = self.consequent).nil? inspector << "└── consequent: ∅\n" else inspector << "└── consequent:\n" inspector << consequent.inspect(inspector.child_inspector(" ")).delete_prefix(inspector.prefix) end inspector.to_str end |
#keyword ⇒ Object
def keyword: () -> String
8908 8909 8910 |
# File 'lib/yarp/node.rb', line 8908 def keyword keyword_loc.slice end |
#operator ⇒ Object
def operator: () -> String?
8913 8914 8915 |
# File 'lib/yarp/node.rb', line 8913 def operator operator_loc&.slice end |