Project

General

Profile

Actions

Feature #7394

open

Enumerable#find ifnone parameter could be non-callable

Added by zzak (zzak _) over 11 years ago. Updated about 3 years ago.

Status:
Assigned
Target version:
-
[ruby-core:49557]

Description

from github:
https://github.com/ruby/ruby/pull/186

In trunk the Enumerable#find method ifnone parameter has to be callable or nil. I found that sometimes I want to return a simple value without wrapping it in a proc. This pull request adds support for non-callable defaults when no items match.

a = [1, 2, 3]

The current behavior

a.find(proc { :foo }) { |x| x > 3 } #=> :foo

With patch

a.find(0) { |x| x > 3 } #=> 0

Files

enumerable_find_noncallable.patch (3.45 KB) enumerable_find_noncallable.patch zzak (zzak _), 11/19/2012 12:36 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0