class SyntaxTree::MethodAddBlock

MethodAddBlock represents a method call with a block argument.

method {}

Attributes

block[R]
BlockNode

the block being sent with the method call

call[R]
ARef | CallNode | Command | CommandCall | Super | ZSuper

the method call

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

Public Class Methods

new(call:, block:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 7573
def initialize(call:, block:, location:)
  @call = call
  @block = block
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 7622
def ===(other)
  other.is_a?(MethodAddBlock) && call === other.call &&
    block === other.block
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 7580
def accept(visitor)
  visitor.visit_method_add_block(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 7584
def child_nodes
  [call, block]
end
Also aliased as: deconstruct
copy(call: nil, block: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 7588
def copy(call: nil, block: nil, location: nil)
  node =
    MethodAddBlock.new(
      call: call || self.call,
      block: block || self.block,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 7602
def deconstruct_keys(_keys)
  { call: call, block: block, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 7606
def format(q)
  # If we're at the top of a call chain, then we're going to do some
  # specialized printing in case we can print it nicely. We _only_ do this
  # at the top of the chain to avoid weird recursion issues.
  if CallChainFormatter.chained?(call) &&
       !CallChainFormatter.chained?(q.parent)
    q.group do
      q
        .if_break { CallChainFormatter.new(self).format(q) }
        .if_flat { format_contents(q) }
    end
  else
    format_contents(q)
  end
end
format_contents(q) click to toggle source
# File lib/syntax_tree/node.rb, line 7627
def format_contents(q)
  q.format(call)
  q.format(block)
end