Class: SyntaxTree::Unless
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.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ 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.
10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 |
# File 'lib/syntax_tree/node.rb', line 10185 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
10183 10184 10185 |
# File 'lib/syntax_tree/node.rb', line 10183 def comments @comments end |
#consequent ⇒ Object (readonly)
- nil, Elsif, Else
-
the next clause in the chain
10180 10181 10182 |
# File 'lib/syntax_tree/node.rb', line 10180 def consequent @consequent end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
10174 10175 10176 |
# File 'lib/syntax_tree/node.rb', line 10174 def predicate @predicate end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be executed
10177 10178 10179 |
# File 'lib/syntax_tree/node.rb', line 10177 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10199 10200 10201 |
# File 'lib/syntax_tree/node.rb', line 10199 def child_nodes [predicate, statements, consequent] end |
#deconstruct_keys(keys) ⇒ Object
10205 10206 10207 10208 10209 10210 10211 10212 10213 |
# File 'lib/syntax_tree/node.rb', line 10205 def deconstruct_keys(keys) { predicate: predicate, statements: statements, consequent: consequent, location: location, comments: comments } end |
#format(q) ⇒ Object
10215 10216 10217 |
# File 'lib/syntax_tree/node.rb', line 10215 def format(q) ConditionalFormatter.new("unless", self).format(q) end |
#pretty_print(q) ⇒ Object
10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 |
# File 'lib/syntax_tree/node.rb', line 10219 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
10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 |
# File 'lib/syntax_tree/node.rb', line 10238 def to_json(*opts) { type: :unless, pred: predicate, stmts: statements, cons: consequent, loc: location, cmts: comments }.to_json(*opts) end |