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.



1665
1666
1667
1668
1669
# File 'lib/syntax_tree/node.rb', line 1665

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



1663
1664
1665
# File 'lib/syntax_tree/node.rb', line 1663

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the block argument



1660
1661
1662
# File 'lib/syntax_tree/node.rb', line 1660

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



1671
1672
1673
# File 'lib/syntax_tree/node.rb', line 1671

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

#child_nodesObject Also known as: deconstruct



1675
1676
1677
# File 'lib/syntax_tree/node.rb', line 1675

def child_nodes
  [name]
end

#deconstruct_keys(keys) ⇒ Object



1681
1682
1683
# File 'lib/syntax_tree/node.rb', line 1681

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

#format(q) ⇒ Object



1685
1686
1687
1688
# File 'lib/syntax_tree/node.rb', line 1685

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