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.



1806
1807
1808
1809
1810
# File 'lib/syntax_tree/node.rb', line 1806

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



1804
1805
1806
# File 'lib/syntax_tree/node.rb', line 1804

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the block argument



1801
1802
1803
# File 'lib/syntax_tree/node.rb', line 1801

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



1812
1813
1814
# File 'lib/syntax_tree/node.rb', line 1812

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

#child_nodesObject Also known as: deconstruct



1816
1817
1818
# File 'lib/syntax_tree/node.rb', line 1816

def child_nodes
  [name]
end

#deconstruct_keys(_keys) ⇒ Object



1822
1823
1824
# File 'lib/syntax_tree/node.rb', line 1822

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

#format(q) ⇒ Object



1826
1827
1828
1829
# File 'lib/syntax_tree/node.rb', line 1826

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