From f413e50ec22046dcdc8655061f9a7a5e5c1b9508 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 11 Oct 2023 11:02:58 -0400 Subject: [PATCH] [ruby/prism] Add Node::type https://github.com/ruby/prism/commit/ca4943e3f9 --- prism/templates/lib/prism/node.rb.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/prism/templates/lib/prism/node.rb.erb b/prism/templates/lib/prism/node.rb.erb index f7937dc3e5..f083e318e0 100644 --- a/prism/templates/lib/prism/node.rb.erb +++ b/prism/templates/lib/prism/node.rb.erb @@ -211,6 +211,16 @@ module Prism def type :<%= node.human %> end + + # Similar to #type, this method returns a symbol that you can use for + # splitting on the type of the node without having to do a long === chain. + # Note that like #type, it will still be slower than using == for a single + # class, but should be faster in a case statement or an array comparison. + # + # def self.type: () -> Symbol + def self.type + :<%= node.human %> + end end <%- end -%> <%- flags.each_with_index do |flag, flag_index| -%>