Method: Enumerator#result!
- Defined in:
- lib/mini_sanity/results.rb
#result!(&block) ⇒ Object
Iterates the Enumerator with a given block
, and checks that the result is not nil. Raises an exception if the result is nil. Otherwise, returns the non-nil result.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mini_sanity/results.rb', line 55 def result!(&block) raise ArgumentError, "Enumerator#result! requires a block" unless block result = self.each(&block) if result.nil? raise MiniSanity::Error.new("Nil result from Enumerator with block", { "Enumerator" => self.inspect, "Block" => MiniSanity::Error.describe_block(&block), }) end result end |