Method: Enumerable#detect_with_value

Defined in:
lib/jinx/helpers/enumerable.rb

#detect_with_value(Object, Object)

Returns the first item and value for which an enumeration on the block given to this method returns a non-nil, non-false value.

Examples:

[1, 2].detect_with_value { |item| item / 2 if item % 2 == 0 } #=> [2, 1]

Returns:

See Also:



116
117
118
119
120
121
122
# File 'lib/jinx/helpers/enumerable.rb', line 116

def detect_with_value
  value = nil
  match = detect do |*item|
    value = yield(*item)
  end
  [match, value]
end