Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/sekisyo.rb
Overview
Define Hash#except and Hash#slice since they do not exist less than Ruby 3.0.
Instance Method Summary collapse
Instance Method Details
#except(*keys) ⇒ Object
17 18 19 20 21 |
# File 'lib/sekisyo.rb', line 17 def except(*keys) hash = dup keys.each(&method(:delete)) hash end |
#slice(*keys) ⇒ Object
23 24 25 26 27 |
# File 'lib/sekisyo.rb', line 23 def slice(*keys) hash = self.class.new keys.each { |k| hash[k] = self[k] if has_key?(k) } hash end |