Module: Interfacets::Client::Utils::MrubyPatches::HashExt

Defined in:
lib/interfacets/client/utils/mruby_patches.rb

Constant Summary collapse

NO_DEFAULT =
Object.new

Instance Method Summary collapse

Instance Method Details

#fetch(k, default = NO_DEFAULT) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/interfacets/client/utils/mruby_patches.rb', line 10

def fetch(k, default = NO_DEFAULT)
  if key?(k)
    self[k]
  elsif block_given?
    yield
  elsif default == NO_DEFAULT
    raise("#{k} not found in #{inspect}")
  else
    default
  end
end