Issue #15918 has been updated by jeremyevans0 (Jeremy Evans).


Sets are supposed to be unordered (any ordering is an implementation detail).  If `Set[1, 2, 3]` matches in your example, so should `Set[3, 2, 1]`, since `Set[1, 2, 3] == Set[3, 2, 1]`.  We could attempt to sort the elements of the set before pattern matching, but some sets contain unsortable elements (e.g. elements of different types).  If pattern matching can work correctly when using `in Set[...]`, then maybe this would be desirable, but I'm not sure if that is possible.  

To answer your question, in my opinion, yes, we shouldn't implement `deconstruct` using `to_a`.

----------------------------------------
Bug #15918: Pattern matching for Set
https://bugs.ruby-lang.org/issues/15918#change-78491

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Currently, `Set` does not respond to `deconstruct`. Shouldn't we implement it using `to_a`?

```
require 'set'
case Set[1, 2, 3]
in [1, 2, 3]
  p "match"
else
  p "no match"
end
# => "no match", should be "match"
```




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