Issue #16341 has been updated by Nondv (Dmitry Non).


The main problem is that implicit conversion can be confusing, especially, if it's not obvious what the resulting proc is going to do.

However, I think that hashes are being used *mainly* for making key-value pairs and accessing them and sets are being used for checking if something is included.
So usage of `:[]` and `:include?` seems appropriate and relatively straight-forward to me.

Of course, depending on the context. With map/reduce/count it does make sense indeed but maybe there're cases when it can make things hard to understand

----------------------------------------
Feature #16341: Proposal: Set#to_proc
https://bugs.ruby-lang.org/issues/16341#change-82648

* Author: Nondv (Dmitry Non)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
``` ruby
class Set
  def to_proc
    -> (x) { include?(x) } # or method(:include?).to_proc
  end
end
```

Usage:

```ruby
require 'set'

banned_numbers = Set[0, 5, 7, 9]
(1..10).reject(&banned_numbers) # ===> [1, 2, 3, 4, 6, 8, 10]
```



-- 
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>