Module: Delight::Enumerator::DetectBang

Defined in:
lib/delight/enumerator/detect_bang.rb

Instance Method Summary collapse

Instance Method Details

#detect!(error_message: nil) ⇒ Object

This method finds required element or raises error if the element is not found. This is similar to sole, but returns first element (so duplicates are possible) but doesn’t need to traverse whole Array.



8
9
10
11
# File 'lib/delight/enumerator/detect_bang.rb', line 8

def detect!(error_message: nil, &)
  default_error_message = "No element found"
  detect(&) || raise(Error::ElementNotFound, error_message || default_error_message)
end