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.
4799 4800 4801 4802 4803 4804 4805 |
# File 'lib/syntax_tree.rb', line 4799 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
4788 4789 4790 |
# File 'lib/syntax_tree.rb', line 4788 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
4791 4792 4793 |
# File 'lib/syntax_tree.rb', line 4791 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4797 4798 4799 |
# File 'lib/syntax_tree.rb', line 4797 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
4785 4786 4787 |
# File 'lib/syntax_tree.rb', line 4785 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4794 4795 4796 |
# File 'lib/syntax_tree.rb', line 4794 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
4807 4808 4809 |
# File 'lib/syntax_tree.rb', line 4807 def child_nodes [keyword, block_var, bodystmt] end |
#format(q) ⇒ Object
4811 4812 4813 |
# File 'lib/syntax_tree.rb', line 4811 def format(q) BlockFormatter.new(self, keyword, "end", bodystmt).format(q) end |
#pretty_print(q) ⇒ Object
4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 |
# File 'lib/syntax_tree.rb', line 4815 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
4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 |
# File 'lib/syntax_tree.rb', line 4831 def to_json(*opts) { type: :do_block, keyword: keyword, block_var: block_var, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |