Class: SyntaxTree::BlockArg
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::BlockArg
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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(name:, location:) ⇒ BlockArg
Returns a new instance of BlockArg.
2198
2199
2200
2201
2202
|
# File 'lib/syntax_tree/node.rb', line 2198
def initialize(name:, location:)
@name = name
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2196
2197
2198
|
# File 'lib/syntax_tree/node.rb', line 2196
def
end
|
#name ⇒ Object
- nil | Ident
-
the name of the block argument
2193
2194
2195
|
# File 'lib/syntax_tree/node.rb', line 2193
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
2234
2235
2236
|
# File 'lib/syntax_tree/node.rb', line 2234
def ===(other)
other.is_a?(BlockArg) && name === other.name
end
|
#accept(visitor) ⇒ Object
2204
2205
2206
|
# File 'lib/syntax_tree/node.rb', line 2204
def accept(visitor)
visitor.visit_blockarg(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
2208
2209
2210
|
# File 'lib/syntax_tree/node.rb', line 2208
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
|
# File 'lib/syntax_tree/node.rb', line 2212
def copy(name: nil, location: nil)
node =
BlockArg.new(
name: name || self.name,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
2225
2226
2227
|
# File 'lib/syntax_tree/node.rb', line 2225
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
2229
2230
2231
2232
|
# File 'lib/syntax_tree/node.rb', line 2229
def format(q)
q.text("&")
q.format(name) if name
end
|