diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f513a6d835b56049fbfe018fee99616cd9526cb..849c230a6701410e45c23d7a2c25a3a26a0b2294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.0 + +* Removed Array#stable_sort_by, since it was not stable and the name was wrong. + ## 0.1.21 * Add Errors.add_parameters(add_to: 'error_report') diff --git a/lib/roqua-support/version.rb b/lib/roqua-support/version.rb index 3495bcd240e75f4f89fec36c425c1ae30b5e0e67..25a34a819efc8a05654b5e557942db785bbcdbbc 100644 --- a/lib/roqua-support/version.rb +++ b/lib/roqua-support/version.rb @@ -1,5 +1,5 @@ module Roqua module Support - VERSION = '0.1.34'.freeze + VERSION = '0.2.0'.freeze end end diff --git a/lib/roqua/core_ext/array/stable_sort_by.rb b/lib/roqua/core_ext/array/stable_sort_by.rb deleted file mode 100644 index 476cc4d55b4388f25c2b67e4ef0493fd948b48ed..0000000000000000000000000000000000000000 --- a/lib/roqua/core_ext/array/stable_sort_by.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Array - # Method for stably sorting elements in an array on multiple attributes. - # - # * Pass the method a block with two arrays containing the attributes for which the - # elements should be subsequently sorted. The first attribute is applied last. - # If for some attribute the sort order should be reversed, the parameters x and y can - # be exchanged between the arrays. - # - # ==== Example - # my_array.stable_sort_by{|x, y| [ - # x.attribute1, - # y.attribute2, - # y.attribute3, - # y.attribute4 - # ] <=> [ - # y.attribute1, - # x.attribute2, - # x.attribute3, - # x.attribute4 - # ]} - # - def stable_sort_by - sort do |x, y| - if not x - -1 - elsif not y - 1 - else - if block_given? - yield x, y - else - x <=> y - end - end - end - end -end \ No newline at end of file diff --git a/spec/roqua/core_ext/array/stable_sort_by_spec.rb b/spec/roqua/core_ext/array/stable_sort_by_spec.rb deleted file mode 100644 index ce534c268c27149c0bcc387b026ba2c571cb6ba1..0000000000000000000000000000000000000000 --- a/spec/roqua/core_ext/array/stable_sort_by_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'roqua/core_ext/array/stable_sort_by' - -describe Array do - describe "#stable_sort_by" do - it "wraps #sort" do - array = [] - array.should_receive(:sort) - array.stable_sort_by - end - - it "sorts nil values before all others" do - [1, nil, 3].stable_sort_by.should == [nil, 1, 3] - end - - it "defaults to regular comparison" do - [1, 3, 2].stable_sort_by.should == [1, 2, 3] - end - - it "accepts a block to do complex comparison" do - [{a: 2, b: 2, c: 3}, - {a: 2, b: 2, c: 4}, - {a: 1, b: 1, c: 6}].stable_sort_by do |x, y| - [x[:a], x[:b], x[:c]] <=> [y[:a], y[:b], y[:c]] - end.should == [{a: 1, b: 1, c: 6}, - {a: 2, b: 2, c: 3}, - {a: 2, b: 2, c: 4}] - end - - it "leaves items in original order if they are the same" do - [{a: 2, b: 2, c: 4}, - {a: 2, b: 1, c: 3}, - {a: 1, b: 3, c: 6}].sort do |x, y| - [x[:a], x[:b]] <=> [y[:a], y[:b]] - end.should == [{a: 1, b: 3, c: 6}, - {a: 2, b: 1, c: 3}, - {a: 2, b: 2, c: 4}] - - end - end -end