Class: SyntaxTree::DoBlock

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(keyword:, block_var:, bodystmt:, location:, comments: []) ⇒ DoBlock



3834
3835
3836
3837
3838
3839
3840
# File 'lib/syntax_tree/node.rb', line 3834

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_varObject (readonly)

nil | BlockVar

the optional variable declaration within this block



3826
3827
3828
# File 'lib/syntax_tree/node.rb', line 3826

def block_var
  @block_var
end

#bodystmtObject (readonly)

BodyStmt

the expressions to be executed within this block



3829
3830
3831
# File 'lib/syntax_tree/node.rb', line 3829

def bodystmt
  @bodystmt
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3832
3833
3834
# File 'lib/syntax_tree/node.rb', line 3832

def comments
  @comments
end

#keywordObject (readonly)

Kw

the do keyword that opens this block



3823
3824
3825
# File 'lib/syntax_tree/node.rb', line 3823

def keyword
  @keyword
end

Instance Method Details

#accept(visitor) ⇒ Object



3842
3843
3844
# File 'lib/syntax_tree/node.rb', line 3842

def accept(visitor)
  visitor.visit_do_block(self)
end

#child_nodesObject Also known as: deconstruct



3846
3847
3848
# File 'lib/syntax_tree/node.rb', line 3846

def child_nodes
  [keyword, block_var, bodystmt]
end

#deconstruct_keys(_keys) ⇒ Object



3852
3853
3854
3855
3856
3857
3858
3859
3860
# File 'lib/syntax_tree/node.rb', line 3852

def deconstruct_keys(_keys)
  {
    keyword: keyword,
    block_var: block_var,
    bodystmt: bodystmt,
    location: location,
    comments: comments
  }
end

#format(q) ⇒ Object



3862
3863
3864
# File 'lib/syntax_tree/node.rb', line 3862

def format(q)
  BlockFormatter.new(self, keyword, "end", bodystmt).format(q)
end