Class: Cistern::Hash
- Inherits:
-
Object
- Object
- Cistern::Hash
- Defined in:
- lib/cistern/hash.rb
Class Method Summary collapse
- .except(hash, *keys) ⇒ Object
-
.except!(hash, *keys) ⇒ Object
Replaces the hash without the given keys.
- .slice(hash, *keys) ⇒ Object
- .stringify_keys(object) ⇒ Object
Class Method Details
.except(hash, *keys) ⇒ Object
8 9 10 |
# File 'lib/cistern/hash.rb', line 8 def self.except(hash, *keys) Cistern::Hash.except!(hash.dup, *keys) end |
.except!(hash, *keys) ⇒ Object
Replaces the hash without the given keys.
13 14 15 16 |
# File 'lib/cistern/hash.rb', line 13 def self.except!(hash, *keys) keys.each { |key| hash.delete(key) } hash end |
.slice(hash, *keys) ⇒ Object
2 3 4 5 6 |
# File 'lib/cistern/hash.rb', line 2 def self.slice(hash, *keys) {}.tap do |sliced| keys.each{ |k| sliced[k] = hash[k] if hash.key?(k) } end end |
.stringify_keys(object) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cistern/hash.rb', line 18 def self.stringify_keys(object) case object when Hash object.inject({}){|r,(k,v)| r.merge(k.to_s => stringify_keys(v))} when Array object.map{|v| stringify_keys(v) } else object end end |