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.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #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.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(keyword:, block_var:, bodystmt:, location:, comments: []) ⇒ DoBlock
Returns a new instance of DoBlock.
3739 3740 3741 3742 3743 3744 3745 |
# File 'lib/syntax_tree/node.rb', line 3739 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
3731 3732 3733 |
# File 'lib/syntax_tree/node.rb', line 3731 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
3734 3735 3736 |
# File 'lib/syntax_tree/node.rb', line 3734 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3737 3738 3739 |
# File 'lib/syntax_tree/node.rb', line 3737 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
3728 3729 3730 |
# File 'lib/syntax_tree/node.rb', line 3728 def keyword @keyword end |
Instance Method Details
#accept(visitor) ⇒ Object
3747 3748 3749 |
# File 'lib/syntax_tree/node.rb', line 3747 def accept(visitor) visitor.visit_do_block(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3751 3752 3753 |
# File 'lib/syntax_tree/node.rb', line 3751 def child_nodes [keyword, block_var, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
3757 3758 3759 3760 3761 3762 3763 3764 3765 |
# File 'lib/syntax_tree/node.rb', line 3757 def deconstruct_keys(_keys) { keyword: keyword, block_var: block_var, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3767 3768 3769 |
# File 'lib/syntax_tree/node.rb', line 3767 def format(q) BlockFormatter.new(self, keyword, "end", bodystmt).format(q) end |