class Prism::ParametersNode
Represents the list of parameters on a method, block, or lambda definition.
def a(b, c, d)
^^^^^^^
end
Public Class Methods
Source
# File lib/prism/node.rb, line 24238 def initialize(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block) @source = source @node_id = node_id @location = location @flags = flags @requireds = requireds @optionals = optionals @rest = rest @posts = posts @keywords = keywords @keyword_rest = keyword_rest @block = block end
Initialize a new ParametersNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 24419 def block @block end
Returns the block attribute.
Source
# File lib/prism/node.rb, line 24409 def keyword_rest @keyword_rest end
Returns the keyword_rest attribute.
Source
# File lib/prism/node.rb, line 24399 def keywords @keywords end
Returns the keywords attribute.
Source
# File lib/prism/node.rb, line 24369 def optionals @optionals end
Returns the optionals attribute.
Source
# File lib/prism/node.rb, line 24389 def posts @posts end
Returns the posts attribute.
Source
# File lib/prism/node.rb, line 24359 def requireds @requireds end
Returns the requireds attribute.
Source
# File lib/prism/node.rb, line 24379 def rest @rest end
Returns the rest attribute.
Source
# File lib/prism/node_ext.rb, line 359 def signature names = [] #: Array[[Symbol, Symbol] | [Symbol]] requireds.each do |param| names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name]) end optionals.each { |param| names << [:opt, param.name] } if (rest = self.rest).is_a?(RestParameterNode) names << [:rest, rest.name || :*] end posts.each do |param| case param when MultiTargetNode names << [:req] when NoKeywordsParameterNode, KeywordRestParameterNode, NoBlockParameterNode, BlockParameterNode, ForwardingParameterNode # Invalid syntax, e.g. "def f(**nil, ...)" moves the NoKeywordsParameterNode to posts raise "Invalid syntax" else names << [:req, param.name] end end # Regardless of the order in which the keywords were defined, the required # keywords always come first followed by the optional keywords. keyopt = [] #: Array[OptionalKeywordParameterNode] keywords.each do |param| if param.is_a?(OptionalKeywordParameterNode) keyopt << param else names << [:keyreq, param.name] end end keyopt.each { |param| names << [:key, param.name] } case (keyword_rest = self.keyword_rest) when ForwardingParameterNode names.concat([[:rest, :*], [:keyrest, :**], [:block, :&]]) when KeywordRestParameterNode names << [:keyrest, keyword_rest.name || :**] when NoKeywordsParameterNode names << [:nokey] end case (block = self.block) when BlockParameterNode names << [:block, block.name || :&] when NoBlockParameterNode names << [:noblock] end names end
Mirrors the Method#parameters method.
Node Interface
These methods are present on all subclasses of Node. Read the node interface docs for more information.
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 24266 def accept(visitor) visitor.visit_parameters_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 24273 def child_nodes [*requireds, *optionals, rest, *posts, *keywords, keyword_rest, block] end
See Node.child_nodes.
Also aliased as: deconstruct
Source
# File lib/prism/node.rb, line 24311 def comment_targets [*requireds, *optionals, *rest, *posts, *keywords, *keyword_rest, *block] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 24296 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(requireds) compact.concat(optionals) if (rest = self.rest); compact << rest; end compact.concat(posts) compact.concat(keywords) if (keyword_rest = self.keyword_rest); compact << keyword_rest; end if (block = self.block); compact << block; end compact end
Source
# File lib/prism/node.rb, line 24321 def copy(node_id: self.node_id, location: self.location, flags: self.flags, requireds: self.requireds, optionals: self.optionals, rest: self.rest, posts: self.posts, keywords: self.keywords, keyword_rest: self.keyword_rest, block: self.block) ParametersNode.new(source, node_id, location, flags, requireds, optionals, rest, posts, keywords, keyword_rest, block) end
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 24281 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? requireds.each { |node| yield node } optionals.each { |node| yield node } if (rest = self.rest); yield rest; end posts.each { |node| yield node } keywords.each { |node| yield node } if (keyword_rest = self.keyword_rest); yield keyword_rest; end if (block = self.block); yield block; end end
See Node.each_child_node.
Repository
Methods related to Relocation.