Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/apns/payload.rb
Overview
module
Instance Method Summary collapse
Instance Method Details
#at_key_path(array_or_dotted_string, &block) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/apns/payload.rb', line 123 def at_key_path(array_or_dotted_string, &block) keypath = array_or_dotted_string.is_a?(Array) ? array_or_dotted_string.dup : array_or_dotted_string.split('.') obj = self while (keypath.count > 0) do key = keypath.shift.to_s key = key.to_sym if !obj.has_key?(key) && obj.has_key?(key.to_sym) next unless keypath.count > 0 # exit the while loop obj = obj.has_key?(key) ? obj[key] : raise("No key #{key} in Object (#{obj.inspect})") end raise("No key #{key} in Object (#{obj.inspect})") unless obj.has_key?(key) if block_given? block.call(obj, key) return self else return obj[key] end end |