Class: SyntaxTree::DoBlock
- Inherits:
-
Object
- Object
- SyntaxTree::DoBlock
- Defined in:
- lib/syntax_tree.rb
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
- #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.
4502 4503 4504 4505 4506 4507 4508 |
# File 'lib/syntax_tree.rb', line 4502 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
4491 4492 4493 |
# File 'lib/syntax_tree.rb', line 4491 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
4494 4495 4496 |
# File 'lib/syntax_tree.rb', line 4494 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4500 4501 4502 |
# File 'lib/syntax_tree.rb', line 4500 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
4488 4489 4490 |
# File 'lib/syntax_tree.rb', line 4488 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4497 4498 4499 |
# File 'lib/syntax_tree.rb', line 4497 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
4510 4511 4512 |
# File 'lib/syntax_tree.rb', line 4510 def child_nodes [keyword, block_var, bodystmt] end |
#format(q) ⇒ Object
4514 4515 4516 |
# File 'lib/syntax_tree.rb', line 4514 def format(q) BlockFormatter.new(self, keyword, bodystmt).format(q) end |
#pretty_print(q) ⇒ Object
4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 |
# File 'lib/syntax_tree.rb', line 4518 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
4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 |
# File 'lib/syntax_tree.rb', line 4534 def to_json(*opts) { type: :do_block, keyword: keyword, block_var: block_var, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |