lib/refinements/hashes.rb in refinements-3.0.0 vs lib/refinements/hashes.rb in refinements-3.1.0
- old
+ new
@@ -15,9 +15,28 @@
def compact!
puts "[DEPRECATION]: #compact! is deprecated and is included, by default, in Ruby 2.4."
reject! { |_, value| value.nil? }
end
+ def symbolize_keys
+ dup.symbolize_keys!
+ end
+
+ def symbolize_keys!
+ keys.each { |key| self[key.to_sym] = delete(key) }
+ self
+ end
+
+ def slice *keys
+ keys.each.with_object({}) do |key, sliced_hash|
+ sliced_hash[key] = self[key] if key?(key)
+ end
+ end
+
+ def slice! *keys
+ replace slice(*keys)
+ end
+
def deep_merge other_hash
dup.deep_merge! other_hash
end
def deep_merge! other_hash