Module: Delight::Enumerator::DetectBang
- Defined in:
- lib/delight/enumerator/detect_bang.rb
Instance Method Summary collapse
-
#detect!(error_message: nil) ⇒ Object
This method finds required element or raises error if the element is not found.
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, &) = "No element found" detect(&) || raise(Error::ElementNotFound, || ) end |