Class: SyntaxTree::MethodAddBlock

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

MethodAddBlock represents a method call with a block argument.

method {}

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(call:, block:, location:, comments: []) ⇒ MethodAddBlock

Returns a new instance of MethodAddBlock.



5514
5515
5516
5517
5518
5519
# File 'lib/syntax_tree/node.rb', line 5514

def initialize(call:, block:, location:, comments: [])
  @call = call
  @block = block
  @location = location
  @comments = comments
end

Instance Attribute Details

#blockObject (readonly)

BraceBlock | DoBlock

the block being sent with the method call



5509
5510
5511
# File 'lib/syntax_tree/node.rb', line 5509

def block
  @block
end

#callObject (readonly)

Call | Command | CommandCall | FCall

the method call



5506
5507
5508
# File 'lib/syntax_tree/node.rb', line 5506

def call
  @call
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



5512
5513
5514
# File 'lib/syntax_tree/node.rb', line 5512

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



5521
5522
5523
# File 'lib/syntax_tree/node.rb', line 5521

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

#child_nodesObject Also known as: deconstruct



5525
5526
5527
# File 'lib/syntax_tree/node.rb', line 5525

def child_nodes
  [call, block]
end

#deconstruct_keys(keys) ⇒ Object



5531
5532
5533
# File 'lib/syntax_tree/node.rb', line 5531

def deconstruct_keys(keys)
  { call: call, block: block, location: location, comments: comments }
end

#format(q) ⇒ Object



5535
5536
5537
5538
# File 'lib/syntax_tree/node.rb', line 5535

def format(q)
  q.format(call)
  q.format(block)
end