summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-05 08:51:10 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 16:42:44 +0000
commit7bcca7177d6c42891004899d63e13ef47d78a337 (patch)
tree35aa71897799886529aaa020bca2e1d312738907 /lib
parent2cb75b8f1760a9aefb2221c4a6fab9304bdb3da2 (diff)
[ruby/prism] Implement hash patterns for ripper translation
https://github.com/ruby/prism/commit/6bd7ae2ed2
Diffstat (limited to 'lib')
-rw-r--r--lib/prism/translation/ripper.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb
index adc82406fa..89f793cb70 100644
--- a/lib/prism/translation/ripper.rb
+++ b/lib/prism/translation/ripper.rb
@@ -1117,7 +1117,25 @@ module Prism
# foo => {}
# ^^
def visit_hash_pattern_node(node)
- raise NoMethodError, __method__
+ constant = visit(node.constant)
+ elements =
+ if node.elements.any? || !node.rest.nil?
+ node.elements.map do |element|
+ bounds(element.key.location)
+ key = on_label(element.key.slice)
+ value = visit(element.value)
+
+ [key, value]
+ end
+ end
+
+ rest =
+ if !node.rest.nil?
+ visit(node.rest.value)
+ end
+
+ bounds(node.location)
+ on_hshptn(constant, elements, rest)
end
# if foo then bar end