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.
10412 10413 10414 10415 10416 10417 |
# File 'lib/syntax_tree.rb', line 10412 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
10410 10411 10412 |
# File 'lib/syntax_tree.rb', line 10410 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10407 10408 10409 |
# File 'lib/syntax_tree.rb', line 10407 def location @location end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to execute
10401 10402 10403 |
# File 'lib/syntax_tree.rb', line 10401 def statement @statement end |
#value ⇒ Object (readonly)
- untyped
-
the value to use if the executed expression raises an error
10404 10405 10406 |
# File 'lib/syntax_tree.rb', line 10404 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
10419 10420 10421 |
# File 'lib/syntax_tree.rb', line 10419 def child_nodes [statement, value] end |
#format(q) ⇒ Object
10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 |
# File 'lib/syntax_tree.rb', line 10423 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
10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 |
# File 'lib/syntax_tree.rb', line 10439 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
10453 10454 10455 10456 10457 10458 10459 10460 10461 |
# File 'lib/syntax_tree.rb', line 10453 def to_json(*opts) { type: :rescue_mod, stmt: statement, value: value, loc: location, cmts: comments }.to_json(*opts) end |