Class: SyntaxTree::Unless
- Inherits:
-
Object
- Object
- SyntaxTree::Unless
- Defined in:
- lib/syntax_tree.rb
Overview
Unless represents the first clause in an unless chain.
unless predicate
end
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#consequent ⇒ Object
readonly
- nil, Elsif, Else
-
the next clause in the chain.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless
constructor
A new instance of Unless.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(predicate:, statements:, consequent:, location:, comments: []) ⇒ Unless
Returns a new instance of Unless.
12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 |
# File 'lib/syntax_tree.rb', line 12473 def initialize( predicate:, statements:, consequent:, location:, comments: [] ) @predicate = predicate @statements = statements @consequent = consequent @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12471 12472 12473 |
# File 'lib/syntax_tree.rb', line 12471 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
12465 12466 12467 |
# File 'lib/syntax_tree.rb', line 12465 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12468 12469 12470 |
# File 'lib/syntax_tree.rb', line 12468 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12459 12460 12461 |
# File 'lib/syntax_tree.rb', line 12459 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
12462 12463 12464 |
# File 'lib/syntax_tree.rb', line 12462 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
12487 12488 12489 |
# File 'lib/syntax_tree.rb', line 12487 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
12491 12492 12493 |
# File 'lib/syntax_tree.rb', line 12491 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#pretty_print(q) ⇒ Object
12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 |
# File 'lib/syntax_tree.rb', line 12495 def pretty_print(q) q.group(2, "(", ")") do q.text("unless") q.breakable q.pp(predicate) q.breakable q.pp(statements) if consequent q.breakable q.pp(consequent) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 |
# File 'lib/syntax_tree.rb', line 12514 def to_json(*opts) { type: :unless, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |