class SyntaxTree::Params
Experimental RBS support (using type sampling data from the type_fusion project).
# sig/syntax_tree/node.rbs class SyntaxTree::Params < SyntaxTree::Node def child_nodes: () -> untyped def empty?: () -> untyped def initialize: (location: SyntaxTree::Location, requireds: (Array[] | Array[SyntaxTree::Ident]), optionals: (Array[] | Array[Array, SyntaxTree::Ident, SyntaxTree::VarRef] | Array[Array, SyntaxTree::Ident, SyntaxTree::HashLiteral]), rest: SyntaxTree::RestParam?, posts: Array[], keywords: Array[], keyword_rest: nil, block: SyntaxTree::BlockArg?) -> void end
def method(param) end
Params represents defining parameters on a method or lambda.
def ===(other)
def ===(other) other.is_a?(Params) && ArrayMatch.call(requireds, other.requireds) && optionals.length == other.optionals.length && optionals .zip(other.optionals) .all? { |left, right| ArrayMatch.call(left, right) } && rest === other.rest && ArrayMatch.call(posts, other.posts) && keywords.length == other.keywords.length && keywords .zip(other.keywords) .all? { |left, right| ArrayMatch.call(left, right) } && keyword_rest === other.keyword_rest && block === other.block end
def accept(visitor)
def accept(visitor) visitor.visit_params(self) end
def arity
has arity 2..4.
end
...
def foo(a, b = 1, c:, d: 2, &block)
by this params node not including the block. For example:
Returns a range representing the possible number of arguments accepted
def arity optional_keywords = keywords.count { |_label, value| value } lower_bound = requireds.length + posts.length + keywords.length - optional_keywords upper_bound = if keyword_rest.nil? && rest.nil? lower_bound + optionals.length + optional_keywords end lower_bound..upper_bound end
def child_nodes
Experimental RBS support (using type sampling data from the type_fusion project).
def child_nodes: () -> untyped
This signature was generated using 5 samples from 1 application.
def child_nodes keyword_rest = self.keyword_rest [ *requireds, *optionals.flatten(1), rest, *posts, *keywords.flatten(1), (keyword_rest if keyword_rest != :nil), block ] end
def copy(
def copy( location: nil, requireds: nil, optionals: nil, rest: nil, posts: nil, keywords: nil, keyword_rest: nil, block: nil ) node = Params.new( location: location || self.location, requireds: requireds || self.requireds, optionals: optionals || self.optionals, rest: rest || self.rest, posts: posts || self.posts, keywords: keywords || self.keywords, keyword_rest: keyword_rest || self.keyword_rest, block: block || self.block ) node.comments.concat(comments.map(&:copy)) node end
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { location: location, requireds: requireds, optionals: optionals, rest: rest, posts: posts, keywords: keywords, keyword_rest: keyword_rest, block: block, comments: comments } end
def empty?
Experimental RBS support (using type sampling data from the type_fusion project).
def empty?: () -> untyped
This signature was generated using 1 sample from 1 application.
declared. This logic accesses every kind of parameter and determines if
to know if they are "empty", which means not having any parameters
Params nodes are the most complicated in the tree. Occasionally you want
def empty? requireds.empty? && optionals.empty? && !rest && posts.empty? && keywords.empty? && !keyword_rest && !block end
def format(q)
def format(q) rest = self.rest keyword_rest = self.keyword_rest parts = [ *requireds, *optionals.map { |(name, value)| OptionalFormatter.new(name, value) } ] parts << rest if rest && !rest.is_a?(ExcessedComma) parts.concat(posts) parts.concat( keywords.map { |(name, value)| KeywordFormatter.new(name, value) } ) parts << KeywordRestFormatter.new(keyword_rest) if keyword_rest parts << block if block if parts.empty? q.nest(0) { format_contents(q, parts) } return end if q.parent.is_a?(DefNode) q.nest(0) do q.text("(") q.group do q.indent do q.breakable_empty format_contents(q, parts) end q.breakable_empty end q.text(")") end else q.nest(0) { format_contents(q, parts) } end end
def format_contents(q, parts)
def format_contents(q, parts) q.seplist(parts) { |part| q.format(part) } q.format(rest) if rest.is_a?(ExcessedComma) end
def initialize(
Experimental RBS support (using type sampling data from the type_fusion project).
def initialize: (location: SyntaxTree::Location, requireds: ( | SyntaxTree::Ident | SyntaxTree::Ident), optionals: ( | Array | SyntaxTree::Ident | SyntaxTree::VarRef | Array | SyntaxTree::Ident | SyntaxTree::ConstPathRef), rest: SyntaxTree::RestParam?, posts: , keywords: , keyword_rest: nil, block: SyntaxTree::BlockArg?) -> void
This signature was generated using 18 samples from 1 application.
def initialize( location:, requireds: [], optionals: [], rest: nil, posts: [], keywords: [], keyword_rest: nil, block: nil ) @requireds = requireds @optionals = optionals @rest = rest @posts = posts @keywords = keywords @keyword_rest = keyword_rest @block = block @location = location @comments = [] end