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.



1777
1778
1779
1780
1781
# File 'lib/syntax_tree/node.rb', line 1777

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



1775
1776
1777
# File 'lib/syntax_tree/node.rb', line 1775

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the block argument



1772
1773
1774
# File 'lib/syntax_tree/node.rb', line 1772

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



1783
1784
1785
# File 'lib/syntax_tree/node.rb', line 1783

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

#child_nodesObject Also known as: deconstruct



1787
1788
1789
# File 'lib/syntax_tree/node.rb', line 1787

def child_nodes
  [name]
end

#deconstruct_keys(_keys) ⇒ Object



1793
1794
1795
# File 'lib/syntax_tree/node.rb', line 1793

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

#format(q) ⇒ Object



1797
1798
1799
1800
# File 'lib/syntax_tree/node.rb', line 1797

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