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
- untyped
-
the expression to execute.
-
#value ⇒ Object
readonly
- untyped
-
the value to use if the executed expression raises an error.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, value:, location:, comments: []) ⇒ RescueMod
constructor
A new instance of RescueMod.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statement:, value:, location:, comments: []) ⇒ RescueMod
Returns a new instance of RescueMod.
8648 8649 8650 8651 8652 8653 |
# File 'lib/syntax_tree/node.rb', line 8648 def initialize(statement:, value:, location:, comments: []) @statement = statement @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8646 8647 8648 |
# File 'lib/syntax_tree/node.rb', line 8646 def comments @comments end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to execute
8640 8641 8642 |
# File 'lib/syntax_tree/node.rb', line 8640 def statement @statement end |
#value ⇒ Object (readonly)
- untyped
-
the value to use if the executed expression raises an error
8643 8644 8645 |
# File 'lib/syntax_tree/node.rb', line 8643 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
8655 8656 8657 |
# File 'lib/syntax_tree/node.rb', line 8655 def child_nodes [statement, value] end |
#deconstruct_keys(keys) ⇒ Object
8661 8662 8663 8664 8665 8666 8667 8668 |
# File 'lib/syntax_tree/node.rb', line 8661 def deconstruct_keys(keys) { statement: statement, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 |
# File 'lib/syntax_tree/node.rb', line 8670 def format(q) q.group(0, "begin", "end") do q.indent do q.breakable(force: true) q.format(statement) end q.breakable(force: true) q.text("rescue StandardError") q.indent do q.breakable(force: true) q.format(value) end q.breakable(force: true) end end |
#pretty_print(q) ⇒ Object
8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 |
# File 'lib/syntax_tree/node.rb', line 8686 def pretty_print(q) q.group(2, "(", ")") do q.text("rescue_mod") q.breakable q.pp(statement) q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8700 8701 8702 8703 8704 8705 8706 8707 8708 |
# File 'lib/syntax_tree/node.rb', line 8700 def to_json(*opts) { type: :rescue_mod, stmt: statement, value: value, loc: location, cmts: comments }.to_json(*opts) end |