Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/sequencescape-api/core_ext/hash.rb
Instance Method Summary collapse
-
#required!(*keys) {|missing| ... } ⇒ Object
Yields all of the missing keys if there are any so that you can do what you like, like error maybe?.
Instance Method Details
#required!(*keys) {|missing| ... } ⇒ Object
Yields all of the missing keys if there are any so that you can do what you like, like error maybe?
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sequencescape-api/core_ext/hash.rb', line 4 def required!(*keys) = keys. return if keys.empty? allowance_method = [:allow_blank] == false ? :blank? : :nil? missing = keys.inject([]) do |missing, next_key| missing.tap do value = self[next_key] missing << next_key if value.send(allowance_method) end end yield(missing) unless missing.empty? end |