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, #pretty_print, #to_json
Constructor Details
#initialize(name:, location:) ⇒ BlockArg
Returns a new instance of BlockArg.
2165
2166
2167
2168
2169
|
# File 'lib/syntax_tree/node.rb', line 2165
def initialize(name:, location:)
@name = name
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2163
2164
2165
|
# File 'lib/syntax_tree/node.rb', line 2163
def
@comments
end
|
#name ⇒ Object
- nil | Ident
-
the name of the block argument
2160
2161
2162
|
# File 'lib/syntax_tree/node.rb', line 2160
def name
@name
end
|
Instance Method Details
#===(other) ⇒ Object
2201
2202
2203
|
# File 'lib/syntax_tree/node.rb', line 2201
def ===(other)
other.is_a?(BlockArg) && name === other.name
end
|
#accept(visitor) ⇒ Object
2171
2172
2173
|
# File 'lib/syntax_tree/node.rb', line 2171
def accept(visitor)
visitor.visit_blockarg(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
2175
2176
2177
|
# File 'lib/syntax_tree/node.rb', line 2175
def child_nodes
[name]
end
|
#copy(name: nil, location: nil) ⇒ Object
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
|
# File 'lib/syntax_tree/node.rb', line 2179
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
2192
2193
2194
|
# File 'lib/syntax_tree/node.rb', line 2192
def deconstruct_keys(_keys)
{ name: name, location: location, comments: }
end
|
2196
2197
2198
2199
|
# File 'lib/syntax_tree/node.rb', line 2196
def format(q)
q.text("&")
q.format(name) if name
end
|