[#61424] [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals — Eric Wong <normalperson@...>

I'm unsure about this. I _hate_ the extra branches this adds;

13 messages 2014/03/12

[ruby-core:61582] [ruby-trunk - Feature #9347] Accept non callable argument to detect

From: ruby-core@...
Date: 2014-03-18 20:50:22 UTC
List: ruby-core #61582
Issue #9347 has been updated by Marc-Andre Lafortune.

Assignee changed from Yukihiro Matsumoto to Marc-Andre Lafortune

I agree, an optional argument would be best. I'll propose a patch. Could we use `if_none` though?

----------------------------------------
Feature #9347: Accept non callable argument to detect
https://bugs.ruby-lang.org/issues/9347#change-45864

* Author: Marc-Andre Lafortune
* Status: Open
* Priority: Normal
* Assignee: Marc-Andre Lafortune
* Category: core
* Target version: current: 2.2.0
----------------------------------------
Currently, the only argument that `Enumerable#detect` accepts is a callable object.

Shouldn't we accept non callable objects too?

    [42].detect(:not_found){} # => NoMethodError: undefined method `call' for :not_found:Symbol
     # would return :not_found instead.

I'd suggest that if the given argument does not `respond_to? :call`, then it would be returned as is instead of raising an error as currently.
Wouldn't this be more flexible and possibly more performant?

Inspired by http://stackoverflow.com/questions/20883414/why-does-enumerabledetect-need-a-proc-lambda



-- 
https://bugs.ruby-lang.org/

In This Thread