feat(support): add params hash with indifferent access

This commit is contained in:
dualfroz committed 2026-08-23 13:20:00 +02:00
1 parent 6cae5b0792
commit 5a96aeb0b9
1 file changed
+36
+36
View File
@@ -0,0 +1,36 @@
module Prism
class Params < Hash
def self.from(source)
source.each_with_object(new) { |(key, value), acc| acc[key] = value }
end
def [](key)
super(convert_key(key))
end
def []=(key, value)
super(convert_key(key), value)
end
def fetch(key, *rest, &block)
super(convert_key(key), *rest, &block)
end
def dig(key, *rest)
super(convert_key(key), *rest)
end
def key?(key)
super(convert_key(key))
end
alias_method :has_key?, :key?
alias_method :include?, :key?
alias_method :member?, :key?
private
def convert_key(key)
key.is_a?(Symbol) ? key.to_s : key
end
end
end