Skip to content

Commit

Permalink
check both HashNode and KeywordHashNode
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Feb 11, 2024
1 parent db02459 commit 808acd5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/prism_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def to_value

# Respond key value and source for hash node
def method_missing(method_name, *args, &block)
return super unless is_a?(HashNode)
return super unless respond_to_elements?

if method_name.to_s.end_with?('_element')
key = method_name.to_s[0..-9]
Expand All @@ -121,7 +121,7 @@ def method_missing(method_name, *args, &block)
end

def respond_to_missing?(method_name, *args)
return super unless is_a?(HashNode)
return super unless respond_to_elements?

if method_name.to_s.end_with?('_element')
key = method_name.to_s[0..-9]
Expand All @@ -136,5 +136,11 @@ def respond_to_missing?(method_name, *args)

super
end

private

def respond_to_elements?
is_a?(HashNode) || is_a?(KeywordHashNode)
end
end
end

0 comments on commit 808acd5

Please sign in to comment.