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.
12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 |
# File 'lib/syntax_tree.rb', line 12261 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
12259 12260 12261 |
# File 'lib/syntax_tree.rb', line 12259 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
12253 12254 12255 |
# File 'lib/syntax_tree.rb', line 12253 def consequent @consequent end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
12256 12257 12258 |
# File 'lib/syntax_tree.rb', line 12256 def location @location end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
12247 12248 12249 |
# File 'lib/syntax_tree.rb', line 12247 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
12250 12251 12252 |
# File 'lib/syntax_tree.rb', line 12250 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
12275 12276 12277 |
# File 'lib/syntax_tree.rb', line 12275 def child_nodes [predicate, statements, consequent] end |
#format(q) ⇒ Object
12279 12280 12281 |
# File 'lib/syntax_tree.rb', line 12279 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#pretty_print(q) ⇒ Object
12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 |
# File 'lib/syntax_tree.rb', line 12283 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
12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 |
# File 'lib/syntax_tree.rb', line 12302 def to_json(*opts) { type: :unless, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |