summaryrefslogtreecommitdiff
path: root/lib/prism/pattern.rb
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-05-03 09:35:32 -0400
committerKevin Newton <[email protected]>2024-05-03 11:11:57 -0400
commit5758e45657f0b2ca8725e67046a1cac92e2e6414 (patch)
tree36a1a99dbdcafc51a7a2d3f01146c9eab76de353 /lib/prism/pattern.rb
parent1d51e929b1b10fe9fa109f8a8ebc3b938827271c (diff)
[ruby/prism] Change ConstantPathNode#child to ConstantPathNode#{name,name_loc}
This has been requested for a long time, and I'm finally doing it now. Unfortunately this is a breaking change for all of the APIs. I've added in a Ruby method for `#child` that is deprecated so that existing usage doesn't break, but for everyone else this is going to be a bit of a pain. https://github.com/ruby/prism/commit/9cbe74464e
Diffstat (limited to 'lib/prism/pattern.rb')
-rw-r--r--lib/prism/pattern.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/prism/pattern.rb b/lib/prism/pattern.rb
index e12cfd597f..91b23afe3e 100644
--- a/lib/prism/pattern.rb
+++ b/lib/prism/pattern.rb
@@ -149,7 +149,7 @@ module Prism
parent = node.parent
if parent.is_a?(ConstantReadNode) && parent.slice == "Prism"
- compile_node(node.child)
+ compile_constant_name(node, node.name)
else
compile_error(node)
end
@@ -158,14 +158,17 @@ module Prism
# in ConstantReadNode
# in String
def compile_constant_read_node(node)
- value = node.slice
+ compile_constant_name(node, node.name)
+ end
- if Prism.const_defined?(value, false)
- clazz = Prism.const_get(value)
+ # Compile a name associated with a constant.
+ def compile_constant_name(node, name)
+ if Prism.const_defined?(name, false)
+ clazz = Prism.const_get(name)
->(other) { clazz === other }
- elsif Object.const_defined?(value, false)
- clazz = Object.const_get(value)
+ elsif Object.const_defined?(name, false)
+ clazz = Object.const_get(name)
->(other) { clazz === other }
else