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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of DoBlock.



3280
3281
3282
3283
3284
3285
3286
# File 'lib/syntax_tree/node.rb', line 3280

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



3272
3273
3274
# File 'lib/syntax_tree/node.rb', line 3272

def block_var
  @block_var
end

#bodystmtObject (readonly)

BodyStmt

the expressions to be executed within this block



3275
3276
3277
# File 'lib/syntax_tree/node.rb', line 3275

def bodystmt
  @bodystmt
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3278
3279
3280
# File 'lib/syntax_tree/node.rb', line 3278

def comments
  @comments
end

#keywordObject (readonly)

Kw

the do keyword that opens this block



3269
3270
3271
# File 'lib/syntax_tree/node.rb', line 3269

def keyword
  @keyword
end

Instance Method Details

#accept(visitor) ⇒ Object



3288
3289
3290
# File 'lib/syntax_tree/node.rb', line 3288

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

#child_nodesObject Also known as: deconstruct



3292
3293
3294
# File 'lib/syntax_tree/node.rb', line 3292

def child_nodes
  [keyword, block_var, bodystmt]
end

#deconstruct_keys(keys) ⇒ Object



3298
3299
3300
3301
3302
3303
3304
3305
3306
# File 'lib/syntax_tree/node.rb', line 3298

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

#format(q) ⇒ Object



3308
3309
3310
# File 'lib/syntax_tree/node.rb', line 3308

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