Closed DanielVartanov closed 4 years ago
Tests failed for older versions of Ruby (<2.3). @piotrmurach if you don't mind I'll fix them only if you choose this path, no point of polishing it if the other path is chosen
Great, I thought the same the very moment I realised I had to remove immutability :+1: Anyway it was good to explore this path, as you see there are something which are better be cherry-picked
Thank you for exploring this path, helped me see the impact of this idea pretty clearly.
Describe the change
It adds
#index
and#<=>
methods toChoice
which makes them sortable insideChoices
.Why are we doing this?
In PR https://github.com/piotrmurach/tty-prompt/pull/141 Piotr suggested
Benefits
@selected.sort_by! { |choice| choices.index(choice) }
can be replaced with@selected.sort!
Drawbacks
Choices#choices
(an Array) from the public API to avoid direct addition without setting an index.Comparable
mixin which requires coherence of<=>
and==
operators.Choice#index
is left mutable from the outside (though not in public API)Requirements
Put an X between brackets on each line if you have done the item: [X] Tests written & passing locally? [X] Code style checked? [X] Rebased with
master
branch? [X] Documentation updated?