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.
4968 4969 4970 4971 4972 4973 4974 |
# File 'lib/syntax_tree.rb', line 4968 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
4957 4958 4959 |
# File 'lib/syntax_tree.rb', line 4957 def block_var @block_var end |
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed within this block
4960 4961 4962 |
# File 'lib/syntax_tree.rb', line 4960 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4966 4967 4968 |
# File 'lib/syntax_tree.rb', line 4966 def comments @comments end |
#keyword ⇒ Object (readonly)
- Kw
-
the do keyword that opens this block
4954 4955 4956 |
# File 'lib/syntax_tree.rb', line 4954 def keyword @keyword end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4963 4964 4965 |
# File 'lib/syntax_tree.rb', line 4963 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
4976 4977 4978 |
# File 'lib/syntax_tree.rb', line 4976 def child_nodes [keyword, block_var, bodystmt] end |
#format(q) ⇒ Object
4980 4981 4982 |
# File 'lib/syntax_tree.rb', line 4980 def format(q) BlockFormatter.new(self, keyword, "end", bodystmt).format(q) end |
#pretty_print(q) ⇒ Object
4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 |
# File 'lib/syntax_tree.rb', line 4984 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
5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 |
# File 'lib/syntax_tree.rb', line 5000 def to_json(*opts) { type: :do_block, keyword: keyword, block_var: block_var, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |