backports 1.16.7 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,14 @@
1
1
  = Packable --- History
2
2
 
3
+ == Version 1.17.0 - May 17th, 2010
4
+
5
+ * Added some features of 1.9.2:
6
+
7
+ * Array#repeated_combination, #repeated_permutation
8
+
3
9
  == Version 1.16.2 - April 11th, 2010
4
10
 
5
- * Added a features of 1.9.2:
11
+ * Added some features of 1.9.2:
6
12
 
7
13
  * Array#uniq, #uniq! (with block)
8
14
  * Array#product (with block)
@@ -110,6 +110,7 @@ but since it is only an imitation, it must be required explicitly:
110
110
  * <tt>rotate, rotate!</tt>
111
111
  * <tt>keep_if, select!</tt>
112
112
  * +product+ (with block)
113
+ * +repeated_combination+, +repeated_permutation+
113
114
  * <tt>sort_by!</tt>
114
115
  * <tt>uniq, #uniq!</tt> (with block)
115
116
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
+ :minor: 17
4
+ :patch: 0
3
5
  :build:
4
- :minor: 16
5
- :patch: 7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "1.16.7"
8
+ s.version = "1.17.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marc-Andr\303\251 Lafortune"]
12
- s.date = %q{2010-05-03}
12
+ s.date = %q{2010-05-17}
13
13
  s.description = %q{ Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
14
14
  }
15
15
  s.email = %q{github@marc-andre.ca}
@@ -7,7 +7,9 @@ module Kernel
7
7
 
8
8
  # Standard in ruby 1.8.7+. See official documentation[http://ruby-doc.org/core-1.9/classes/Object.html]
9
9
  def instance_exec(*arg, &block)
10
- define_singleton_method(:"temporary method for instance_exec", &block)
10
+ class << self
11
+ self
12
+ end.send(:define_method, :"temporary method for instance_exec", &block)
11
13
  send(:"temporary method for instance_exec", *arg)
12
14
  end unless method_defined? :instance_exec
13
15
 
@@ -27,6 +27,43 @@ class Array
27
27
  Backports.alias_method_chain self, :product, :block
28
28
  end
29
29
 
30
+ # Note: Combinations are not yielded in the same order as MRI.
31
+ # This is not a bug; the spec states that the order is implementation dependent
32
+ def repeated_combination(num, &block)
33
+ return to_enum :repeated_combination, num unless block_given?
34
+ num = Backports.coerce_to_int(num)
35
+ if num <= 0
36
+ yield [] if num == 0
37
+ else
38
+ indices = Array.new(num, 0)
39
+ indices[-1] = size
40
+ while dec = indices.find_index(&:nonzero?)
41
+ indices[0..dec] = Array.new dec+1, indices[dec]-1
42
+ yield values_at(*indices)
43
+ end
44
+ end
45
+ self
46
+ end unless method_defined? :repeated_combination
47
+
48
+ # Note: Permutations are not yielded in the same order as MRI.
49
+ # This is not a bug; the spec states that the order is implementation dependent
50
+ def repeated_permutation(num, &block)
51
+ return to_enum :repeated_permutation, num unless block_given?
52
+ num = Backports.coerce_to_int(num)
53
+ if num <= 0
54
+ yield [] if num == 0
55
+ else
56
+ indices = Array.new(num, 0)
57
+ indices[-1] = size
58
+ while dec = indices.find_index(&:nonzero?)
59
+ indices[0...dec] = Array.new dec, size-1
60
+ indices[dec] -= 1
61
+ yield values_at(*indices)
62
+ end
63
+ end
64
+ self
65
+ end unless method_defined? :repeated_permutation
66
+
30
67
  def rotate(n=1)
31
68
  dup.rotate!(n)
32
69
  end unless method_defined? :rotate
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 16
8
- - 7
9
- version: 1.16.7
7
+ - 17
8
+ - 0
9
+ version: 1.17.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-03 00:00:00 -04:00
17
+ date: 2010-05-17 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20