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.
12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 |
# File 'lib/syntax_tree.rb', line 12341 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
12339 12340 12341 |
# File 'lib/syntax_tree.rb', line 12339 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
12333 12334 12335 |
# File 'lib/syntax_tree.rb', line 12333 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12336 12337 12338 |
# File 'lib/syntax_tree.rb', line 12336 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12327 12328 12329 |
# File 'lib/syntax_tree.rb', line 12327 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
12330 12331 12332 |
# File 'lib/syntax_tree.rb', line 12330 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
12355 12356 12357 |
# File 'lib/syntax_tree.rb', line 12355 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
12359 12360 12361 |
# File 'lib/syntax_tree.rb', line 12359 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#pretty_print(q) ⇒ Object
12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 |
# File 'lib/syntax_tree.rb', line 12363 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
12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 |
# File 'lib/syntax_tree.rb', line 12382 def to_json(*opts) { type: :unless, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |