From 9ba96e03a8b5baa098c7ac6841e4c021b02f1910 Mon Sep 17 00:00:00 2001 From: Jack Jennings Date: Tue, 6 Apr 2021 17:45:02 -0700 Subject: Add #except under Ruby 3 Ruby 3 adds the Hash#except method, which should return the correct Hashie object instance when called on a Mash or object using the Hashie::Extensions::IndifferentAccess mixin. --- lib/hashie/extensions/indifferent_access.rb | 7 +++++++ lib/hashie/mash.rb | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/hashie/extensions/indifferent_access.rb b/lib/hashie/extensions/indifferent_access.rb index d6b9da3..c2c7888 100644 --- a/lib/hashie/extensions/indifferent_access.rb +++ b/lib/hashie/extensions/indifferent_access.rb @@ -162,6 +162,13 @@ module Hashie end end + with_minimum_ruby('3.0.0') do + def except(*keys) + string_keys = keys.map { |key| convert_key(key) } + super(*string_keys) + end + end + protected def hash_lacking_indifference?(other) diff --git a/lib/hashie/mash.rb b/lib/hashie/mash.rb index f72633d..d5cb308 100644 --- a/lib/hashie/mash.rb +++ b/lib/hashie/mash.rb @@ -351,6 +351,13 @@ module Hashie end end + with_minimum_ruby('3.0.0') do + def except(*keys) + string_keys = keys.map { |key| convert_key(key) } + self.class.new(super(*string_keys)) + end + end + protected def method_name_and_suffix(method_name) -- cgit v1.2.1