Class: SyntaxTree::IfMod
Overview
IfMod represents the modifier form of an if statement.
expression if predicate
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#predicate ⇒ Object
readonly
- untyped
-
the expression to be checked.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statement:, predicate:, location:, comments: []) ⇒ IfMod
constructor
A new instance of IfMod.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statement:, predicate:, location:, comments: []) ⇒ IfMod
Returns a new instance of IfMod.
6111 6112 6113 6114 6115 6116 |
# File 'lib/syntax_tree/node.rb', line 6111 def initialize(statement:, predicate:, location:, comments: []) @statement = statement @predicate = predicate @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
6109 6110 6111 |
# File 'lib/syntax_tree/node.rb', line 6109 def comments @comments end |
#predicate ⇒ Object (readonly)
- untyped
-
the expression to be checked
6106 6107 6108 |
# File 'lib/syntax_tree/node.rb', line 6106 def predicate @predicate end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed
6103 6104 6105 |
# File 'lib/syntax_tree/node.rb', line 6103 def statement @statement end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
6118 6119 6120 |
# File 'lib/syntax_tree/node.rb', line 6118 def child_nodes [statement, predicate] end |
#deconstruct_keys(keys) ⇒ Object
6124 6125 6126 6127 6128 6129 6130 6131 |
# File 'lib/syntax_tree/node.rb', line 6124 def deconstruct_keys(keys) { statement: statement, predicate: predicate, location: location, comments: comments } end |
#format(q) ⇒ Object
6133 6134 6135 |
# File 'lib/syntax_tree/node.rb', line 6133 def format(q) ConditionalModFormatter.new("if", self).format(q) end |
#pretty_print(q) ⇒ Object
6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 |
# File 'lib/syntax_tree/node.rb', line 6137 def pretty_print(q) q.group(2, "(", ")") do q.text("if_mod") q.breakable q.pp(statement) q.breakable q.pp(predicate) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6151 6152 6153 6154 6155 6156 6157 6158 6159 |
# File 'lib/syntax_tree/node.rb', line 6151 def to_json(*opts) { type: :if_mod, stmt: statement, pred: predicate, loc: location, cmts: comments }.to_json(*opts) end |