[#91458] [Ruby trunk Feature#4475] default variable name for parameter — matz@...
Issue #4475 has been updated by matz (Yukihiro Matsumoto).
3 messages
2019/02/07
[ruby-core:91537] [Ruby trunk Feature#7394] Enumerable#find ifnone parameter could be non-callable
From:
samuel@...
Date:
2019-02-13 22:08:55 UTC
List:
ruby-core #91537
Issue #7394 has been updated by ioquatix (Samuel Williams).
Just because it might cause some surprise, perhaps we can use keyword argument for this.
e.g.
```ruby
a = [1, 2, 3]
a.find(else: 0) { |x| x > 3 } #=> 0
```
I kind of prefer original suggestion, but I can imagine if passing an object that responds to `#call` it might have unexpected behaviour.
----------------------------------------
Feature #7394: Enumerable#find ifnone parameter could be non-callable
https://bugs.ruby-lang.org/issues/7394#change-76794
* Author: zzak (Zachary Scott)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version:
----------------------------------------
=begin
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}))
=end
---Files--------------------------------
enumerable_find_noncallable.patch (3.45 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>