Feature #16989


Sets: need ♥️

Added by marcandre (Marc-Andre Lafortune) about 1 year ago. Updated 3 months ago.

Target version:


I am opening a series of feature requests on Set, all of them based on this usecase.

The main usecase I have in mind is my recent experience with RuboCop. I noticed a big number of frozen arrays being used only to later call include? on them. This is O(n) instead of O(1).

Trying to convert them to Sets causes major compatibility issues, as well as very frustrating situations and some cases that would make them much less efficient.

Because of these incompatibilities, RuboCop is in the process of using a custom class based on Array with optimized include? and ===. RuboCop runs multiple checks on Ruby code. Those checks are called cops. RuboCop performance is (IMO) pretty bad and some cops currently are in O(n^2) where n is the size of the code being inspected. Even given these extremely inefficient cops, optimizing the 100+ such arrays (most of which are quite small btw) gave a 5% speed boost.

RuboCop PRs for reference:

My experience tells me that there are many other opportunities to use Sets that are missed because Sets are not builtin, not known enough and have no shorthand notation.

In this issue I'd like to concentrate the discussion on the following request: Sets should be core objects, in the same way that Complex were not and are now. Some of the upcoming feature requests would be easier (or only possible) to implement were Sets builtin.

Related issues

Related to Ruby master - Feature #16990: Sets: operators compatibility with ArrayOpenActions
Related to Ruby master - Feature #16991: Sets: add Set#joinOpenActions
Related to Ruby master - Feature #16992: Sets: officially orderedOpenmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #16993: Sets: from hash keys using Hash#key_setOpenActions
Related to Ruby master - Feature #16994: Sets: shorthand for frozen sets of symbols / stringsFeedbackActions
Related to Ruby master - Feature #16995: Sets: <=> should be specializedOpenActions

Also available in: Atom PDF