Class: SyntaxTree::Else
- Inherits:
-
Object
- Object
- SyntaxTree::Else
- Defined in:
- lib/syntax_tree.rb
Overview
Else represents the end of an if, unless, or case chain.
if variable
else
end
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.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ Else
constructor
A new instance of Else.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ Else
Returns a new instance of Else.
5421 5422 5423 5424 5425 |
# File 'lib/syntax_tree.rb', line 5421 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5419 5420 5421 |
# File 'lib/syntax_tree.rb', line 5419 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5416 5417 5418 |
# File 'lib/syntax_tree.rb', line 5416 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5413 5414 5415 |
# File 'lib/syntax_tree.rb', line 5413 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5427 5428 5429 |
# File 'lib/syntax_tree.rb', line 5427 def child_nodes [statements] end |
#format(q) ⇒ Object
5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 |
# File 'lib/syntax_tree.rb', line 5431 def format(q) q.group do q.text("else") unless statements.empty? q.indent do q.breakable(force: true) q.format(statements) end end end end |
#pretty_print(q) ⇒ Object
5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 |
# File 'lib/syntax_tree.rb', line 5444 def pretty_print(q) q.group(2, "(", ")") do q.text("else") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5455 5456 5457 5458 5459 |
# File 'lib/syntax_tree.rb', line 5455 def to_json(*opts) { type: :else, stmts: statements, loc: location, cmts: comments }.to_json( *opts ) end |