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

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(name:, location:, comments: []) ⇒ BlockArg

Returns a new instance of BlockArg.



1730
1731
1732
1733
1734
# File 'lib/syntax_tree/node.rb', line 1730

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



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

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the block argument



1725
1726
1727
# File 'lib/syntax_tree/node.rb', line 1725

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



1736
1737
1738
# File 'lib/syntax_tree/node.rb', line 1736

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

#child_nodesObject Also known as: deconstruct



1740
1741
1742
# File 'lib/syntax_tree/node.rb', line 1740

def child_nodes
  [name]
end

#deconstruct_keys(_keys) ⇒ Object



1746
1747
1748
# File 'lib/syntax_tree/node.rb', line 1746

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

#format(q) ⇒ Object



1750
1751
1752
1753
# File 'lib/syntax_tree/node.rb', line 1750

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