Class: SyntaxTree::DoBlock
Overview
DoBlock represents passing a block to a method call using the do
and end
keywords.
method do |value|
end
Instance Attribute Summary collapse
-
#block_var ⇒ Object
readonly
- nil | BlockVar
-
the optional variable declaration within this block.
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed within this block.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#keyword ⇒ Object
readonly
- Kw
-
the do keyword that opens this block.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(keyword:, block_var:, bodystmt:, location:, comments: []) ⇒ DoBlock
constructor
A new instance of DoBlock.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(keyword:, block_var:, bodystmt:, location:, comments: []) ⇒ DoBlock
Returns a new instance of DoBlock.
4234 4235 4236 4237 4238 4239 4240 |
# File 'lib/syntax_tree/node.rb', line 4234 def initialize(keyword:, block_var:, bodystmt:, location:, comments: []) @keyword = keyword @block_var = block_var @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#block_var ⇒ Object (readonly)
- nil | BlockVar
-
the optional variable declaration within this block
4223 4224 4225 |
# File 'lib/syntax_tree/node.rb', line 4223 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
4226 4227 4228 |
# File 'lib/syntax_tree/node.rb', line 4226 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4232 4233 4234 |
# File 'lib/syntax_tree/node.rb', line 4232 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
4220 4221 4222 |
# File 'lib/syntax_tree/node.rb', line 4220 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4229 4230 4231 |
# File 'lib/syntax_tree/node.rb', line 4229 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
4242 4243 4244 |
# File 'lib/syntax_tree/node.rb', line 4242 def child_nodes [keyword, block_var, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
4248 4249 4250 4251 4252 4253 4254 4255 4256 |
# File 'lib/syntax_tree/node.rb', line 4248 def deconstruct_keys(keys) { keyword: keyword, block_var: block_var, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
4258 4259 4260 |
# File 'lib/syntax_tree/node.rb', line 4258 def format(q) BlockFormatter.new(self, keyword, "end", bodystmt).format(q) end |
#pretty_print(q) ⇒ Object
4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 |
# File 'lib/syntax_tree/node.rb', line 4262 def pretty_print(q) q.group(2, "(", ")") do q.text("do_block") if block_var q.breakable q.pp(block_var) end q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 |
# File 'lib/syntax_tree/node.rb', line 4278 def to_json(*opts) { type: :do_block, keyword: keyword, block_var: block_var, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |