Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/memotoo/core-ext/hash.rb
Overview
use with: @key_i_need = @event.seek :coordinator, :api_license, :key instead of: @key_i_need = @event[:api_license]
Instance Method Summary collapse
-
#deep_merge_me!(other_hash) ⇒ Object
Returns a new Hash with
self
andother_hash
merged recursively. -
#seek(_keys_ = []) ⇒ Object
:nodoc: all.
Instance Method Details
#deep_merge_me!(other_hash) ⇒ Object
Returns a new Hash with self
and other_hash
merged recursively. Modifies the receiver in place.
> see this function also in savon gem
got problems in my test and had to include it hereā¦
31 32 33 34 35 36 37 |
# File 'lib/memotoo/core-ext/hash.rb', line 31 def deep_merge_me!(other_hash) other_hash.each_pair do |k,v| tv = self[k] self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge_me!(v) : v end self end |
#seek(_keys_ = []) ⇒ Object
:nodoc: all
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/memotoo/core-ext/hash.rb', line 8 def seek(_keys_=[]) last_level = self sought_value = nil _keys_.each_with_index do |_key_, _idx_| if last_level.is_a?(Hash) && last_level.has_key?(_key_) if _idx_ + 1 == _keys_.length sought_value = last_level[_key_] else last_level = last_level[_key_] end else break end end sought_value end |