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.
4836 4837 4838 4839 4840 4841 4842 |
# File 'lib/syntax_tree.rb', line 4836 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
4825 4826 4827 |
# File 'lib/syntax_tree.rb', line 4825 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
4828 4829 4830 |
# File 'lib/syntax_tree.rb', line 4828 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4834 4835 4836 |
# File 'lib/syntax_tree.rb', line 4834 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
4822 4823 4824 |
# File 'lib/syntax_tree.rb', line 4822 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4831 4832 4833 |
# File 'lib/syntax_tree.rb', line 4831 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
4844 4845 4846 |
# File 'lib/syntax_tree.rb', line 4844 def child_nodes [keyword, block_var, bodystmt] end |
#format(q) ⇒ Object
4848 4849 4850 |
# File 'lib/syntax_tree.rb', line 4848 def format(q) BlockFormatter.new(self, keyword, "end", bodystmt).format(q) end |
#pretty_print(q) ⇒ Object
4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 |
# File 'lib/syntax_tree.rb', line 4852 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
4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 |
# File 'lib/syntax_tree.rb', line 4868 def to_json(*opts) { type: :do_block, keyword: keyword, block_var: block_var, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |