lib/refinements/hashes.rb in refinements-7.5.0 vs lib/refinements/hashes.rb in refinements-7.6.0
- old
+ new
@@ -1,8 +1,18 @@
# frozen_string_literal: true
module Refinements
module Hashes
+ refine Hash.singleton_class do
+ def infinite
+ new { |new_hash, missing_key| new_hash[missing_key] = new(&new_hash.default_proc) }
+ end
+
+ def with_default value
+ new { |new_hash, missing_key| new_hash[missing_key] = value }
+ end
+ end
+
refine Hash do
def except *keys
reject { |key, _value| keys.include? key }
end