Sha256: 20e4741dd3a62aa4593794eb8e13f34e2206260ec8500148c3c67de73d7dbd3f
Contents?: true
Size: 649 Bytes
Versions: 18
Compression:
Stored size: 649 Bytes
Contents
module DuckPuncher module Ducks module Hash # http://coryodaniel.com/index.php/2009/12/30/ruby-getting-deeply-nested-values-from-a-hash-in-one-line-of-code/ def dig(*_keys_) last_level = self sought_value = nil _keys_.each_with_index do |_key_, _idx_| break unless last_level.respond_to?(:has_key?) break unless last_level.has_key?(_key_) if _idx_ + 1 == _keys_.length sought_value = last_level[_key_] else last_level = last_level[_key_] end end sought_value end unless method_defined?(:dig) end end end
Version data entries
18 entries across 18 versions & 1 rubygems