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.
5252 5253 5254 5255 5256 |
# File 'lib/syntax_tree.rb', line 5252 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
5250 5251 5252 |
# File 'lib/syntax_tree.rb', line 5250 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5247 5248 5249 |
# File 'lib/syntax_tree.rb', line 5247 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
5244 5245 5246 |
# File 'lib/syntax_tree.rb', line 5244 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
5258 5259 5260 |
# File 'lib/syntax_tree.rb', line 5258 def child_nodes [statements] end |
#format(q) ⇒ Object
5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 |
# File 'lib/syntax_tree.rb', line 5262 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
5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 |
# File 'lib/syntax_tree.rb', line 5275 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
5286 5287 5288 5289 5290 |
# File 'lib/syntax_tree.rb', line 5286 def to_json(*opts) { type: :else, stmts: statements, loc: location, cmts: comments }.to_json( *opts ) end |