Class: SyntaxTree::BlockArg

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

Overview

BlockArg represents declaring a block parameter on a method definition.

def method(&block); 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(name:, location:, comments: []) ⇒ BlockArg

Returns a new instance of BlockArg.



1713
1714
1715
1716
1717
# File 'lib/syntax_tree/node.rb', line 1713

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1711
1712
1713
# File 'lib/syntax_tree/node.rb', line 1711

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the block argument



1708
1709
1710
# File 'lib/syntax_tree/node.rb', line 1708

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



1719
1720
1721
# File 'lib/syntax_tree/node.rb', line 1719

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

#child_nodesObject Also known as: deconstruct



1723
1724
1725
# File 'lib/syntax_tree/node.rb', line 1723

def child_nodes
  [name]
end

#deconstruct_keys(keys) ⇒ Object



1729
1730
1731
# File 'lib/syntax_tree/node.rb', line 1729

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

#format(q) ⇒ Object



1733
1734
1735
1736
# File 'lib/syntax_tree/node.rb', line 1733

def format(q)
  q.text("&")
  q.format(name) if name
end