ruby19_stable_sort 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby19_stable_sort.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ module Enumerable
2
+ def stable_sort_by(&block)
3
+ sort_by.with_index {|item, index| [block[item], index] }
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Ruby19StableSort
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby19_stable_sort/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby19_stable_sort"
7
+ s.version = Ruby19StableSort::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jon Moses"]
10
+ s.email = ["jon@burningbush.us"]
11
+ s.homepage = ""
12
+ s.summary = %q{Implement a stable sort_by method.}
13
+ s.description = %q{The Ruby 1.8 Enumerable.sort_by method was stable, in that items with matching conditions were
14
+ preserved in the same order. That's not the case in Ruby 1.9. Some of my code depended on this behavior,
15
+ and I'm sure I'm not the only one. So here's a stable_sort_by method that preserves the orders of items with
16
+ matching sort_by values.}
17
+
18
+ #s.rubyforge_project = "ruby19_stable_sort"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,12 @@
1
+ require 'minitest/autorun'
2
+ require 'ruby19_stable_sort'
3
+
4
+ class Ruby19StableSortTest < MiniTest::Unit::TestCase
5
+ def test_that_sort_by_still_works
6
+ assert_equal [[:a, 0], [:b, 1], [:d, 2], [:c, 2], [:e, 3]], [ [:a, 0], [:b, 1], [:c, 2], [:d, 2], [:e, 3] ].sort_by {|x| x[1] }
7
+ end
8
+
9
+ def test_that_stable_sort_by_is_stable
10
+ assert_equal [[:a, 0], [:b, 1], [:c, 2], [:d, 2], [:e, 3]], [ [:a, 0], [:b, 1], [:c, 2], [:d, 2], [:e, 3] ].stable_sort_by {|x| x[1] }
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby19_stable_sort
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jon Moses
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-24 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: |-
18
+ The Ruby 1.8 Enumerable.sort_by method was stable, in that items with matching conditions were
19
+ preserved in the same order. That's not the case in Ruby 1.9. Some of my code depended on this behavior,
20
+ and I'm sure I'm not the only one. So here's a stable_sort_by method that preserves the orders of items with
21
+ matching sort_by values.
22
+ email:
23
+ - jon@burningbush.us
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - lib/ruby19_stable_sort.rb
35
+ - lib/ruby19_stable_sort/version.rb
36
+ - ruby19_stable_sort.gemspec
37
+ - test/ruby19_stable_sort_test.rb
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.5.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Implement a stable sort_by method.
66
+ test_files:
67
+ - test/ruby19_stable_sort_test.rb