Method: Enumerable#detect_value

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

#detect_valueObject

Returns the first non-nil, non-false enumerated value resulting from a call to the block given to this method, or nil if no value detected.

Examples:

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

Returns:

  • the detected block result

See Also:



101
102
103
104
105
106
107
# File 'lib/jinx/helpers/enumerable.rb', line 101

def detect_value
  each do |*item|
    value = yield(*item)
    return value if value
  end
  nil
end