Class: SyntaxTree::RescueMod
- Inherits:
-
Object
- Object
- SyntaxTree::RescueMod
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of 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.
Instance Method Summary collapse
- #child_nodes ⇒ 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.
10544 10545 10546 10547 10548 10549 |
# File 'lib/syntax_tree.rb', line 10544 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
10542 10543 10544 |
# File 'lib/syntax_tree.rb', line 10542 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10539 10540 10541 |
# File 'lib/syntax_tree.rb', line 10539 def location @location end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to execute
10533 10534 10535 |
# File 'lib/syntax_tree.rb', line 10533 def statement @statement end |
#value ⇒ Object (readonly)
- untyped
-
the value to use if the executed expression raises an error
10536 10537 10538 |
# File 'lib/syntax_tree.rb', line 10536 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
10551 10552 10553 |
# File 'lib/syntax_tree.rb', line 10551 def child_nodes [statement, value] end |
#format(q) ⇒ Object
10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 |
# File 'lib/syntax_tree.rb', line 10555 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
10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 |
# File 'lib/syntax_tree.rb', line 10571 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
10585 10586 10587 10588 10589 10590 10591 10592 10593 |
# File 'lib/syntax_tree.rb', line 10585 def to_json(*opts) { type: :rescue_mod, stmt: statement, value: value, loc: location, cmts: comments }.to_json(*opts) end |