Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/first_existing/hash.rb

Instance Method Summary collapse

Instance Method Details

#default!(key, *fallbacks) ⇒ Object Also known as: defaults!



2
3
4
5
6
7
# File 'lib/first_existing/hash.rb', line 2

def default! key, *fallbacks
  return self[key] if key? key

  fallback = first_existing(*fallbacks)
  self[key] = fallback unless fallback.nil?
end

#required!(key) ⇒ Object



10
11
12
# File 'lib/first_existing/hash.rb', line 10

def required! key
  raise "The '#{key}' option is required!" unless key? key
end