summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/node_ext.rb52
1 files changed, 49 insertions, 3 deletions
diff --git a/lib/prism/node_ext.rb b/lib/prism/node_ext.rb
index 8d8bee074d..4febc615c1 100644
--- a/lib/prism/node_ext.rb
+++ b/lib/prism/node_ext.rb
@@ -61,7 +61,8 @@ module Prism
end
class ConstantReadNode < Node
- # Returns the list of parts for the full name of this constant. For example: [:Foo]
+ # Returns the list of parts for the full name of this constant.
+ # For example: [:Foo]
def full_name_parts
[name]
end
@@ -73,7 +74,8 @@ module Prism
end
class ConstantPathNode < Node
- # Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]
+ # Returns the list of parts for the full name of this constant path.
+ # For example: [:Foo, :Bar]
def full_name_parts
parts = [child.name]
current = parent
@@ -93,7 +95,8 @@ module Prism
end
class ConstantPathTargetNode < Node
- # Returns the list of parts for the full name of this constant path. For example: [:Foo, :Bar]
+ # Returns the list of parts for the full name of this constant path.
+ # For example: [:Foo, :Bar]
def full_name_parts
(parent&.full_name_parts || [:""]).push(child.name)
end
@@ -103,4 +106,47 @@ module Prism
full_name_parts.join("::")
end
end
+
+ class ParametersNode < Node
+ # Mirrors the Method#parameters method.
+ def signature
+ names = []
+
+ requireds.each do |param|
+ names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name])
+ end
+
+ optionals.each { |param| names << [:opt, param.name] }
+ names << [:rest, rest.name || :*] if rest
+
+ posts.each do |param|
+ names << (param.is_a?(MultiTargetNode) ? [:req] : [:req, param.name])
+ end
+
+ # Regardless of the order in which the keywords were defined, the required
+ # keywords always come first followed by the optional keywords.
+ keyopt = []
+ 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
+ when ForwardingParameterNode
+ names.concat([[:rest, :*], [:keyrest, :**], [:block, :&]])
+ when KeywordRestParameterNode
+ names << [:keyrest, keyword_rest.name || :**]
+ when NoKeywordsParameterNode
+ names << [:nokey]
+ end
+
+ names << [:block, block.name || :&] if block
+ names
+ end
+ end
end