Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ext/hash.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#-(other) ⇒ Object
Extracted from Ruby Facets: Operator for remove hash paris.
- #assert_required_keys(keys) ⇒ Object
Instance Method Details
#-(other) ⇒ Object
Extracted from Ruby Facets: Operator for remove hash paris. If another hash is given the pairs are only removed if both key and value are equal. If an array is given then matching keys are removed.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ext/hash.rb', line 12 def -(other) h = self.dup if other.respond_to?(:to_ary) other.to_ary.each do |k| h.delete(k) end else other.each do |k,v| if h.key?(k) h.delete(k) if v == h[k] end end end h end |
#assert_required_keys(keys) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/ext/hash.rb', line 3 def assert_required_keys(keys) for key in keys raise(ArgumentError, "Missing required key(s): #{key}") unless self.keys.include?(key) end true end |