Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/l43/core/enum/hash.rb
Instance Method Summary collapse
- #fetch_any(*keys, default: L43::Core::None, &blk) ⇒ Object
- #fetch_any!(*keys, default: L43::Core::None, &blk) ⇒ Object
Instance Method Details
#fetch_any(*keys, default: L43::Core::None, &blk) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/l43/core/enum/hash.rb', line 7 def fetch_any(*keys, default: L43::Core::None, &blk) raise ArgumentError, "ambigous default definition, (&block and default: provided)" if blk && default != L43::Core::None keys = keys.flatten raise ArgumentError, "no keys provided to look for" if keys.empty? keys.each do |key| return L43::Core::Result.ok(fetch(key)) if has_key? key end return L43::Core::Result.ok(blk.()) if blk return L43::Core::Result.ok(default) unless default == L43::Core::None L43::Core::Result.error "no key found from #{keys.inspect}" end |