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.
5289 5290 5291 5292 5293 |
# File 'lib/syntax_tree.rb', line 5289 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
5287 5288 5289 |
# File 'lib/syntax_tree.rb', line 5287 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5284 5285 5286 |
# File 'lib/syntax_tree.rb', line 5284 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5281 5282 5283 |
# File 'lib/syntax_tree.rb', line 5281 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5295 5296 5297 |
# File 'lib/syntax_tree.rb', line 5295 def child_nodes [statements] end |
#format(q) ⇒ Object
5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 |
# File 'lib/syntax_tree.rb', line 5299 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
5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 |
# File 'lib/syntax_tree.rb', line 5312 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
5323 5324 5325 5326 5327 |
# File 'lib/syntax_tree.rb', line 5323 def to_json(*opts) { type: :else, stmts: statements, loc: location, cmts: comments }.to_json( *opts ) end |