backports 1.16.1 → 1.16.2

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.
@@ -1,10 +1,11 @@
1
1
  = Packable --- History
2
2
 
3
- == Version 1.16.1 - April 11th, 2010
3
+ == Version 1.16.2 - April 11th, 2010
4
4
 
5
5
  * Added a features of 1.9.2:
6
6
 
7
7
  * Array#uniq, #uniq! (with block)
8
+ * Array#product (with block)
8
9
  * Dir.home
9
10
  * Hash#keep_if, select!
10
11
  * Random (new class)
@@ -109,6 +109,7 @@ but since it is only an imitation, it must be required explicitly:
109
109
  * Array
110
110
  * <tt>rotate, rotate!</tt>
111
111
  * <tt>keep_if, select!</tt>
112
+ * +product+ (with block)
112
113
  * <tt>sort_by!</tt>
113
114
  * <tt>uniq, #uniq!</tt> (with block)
114
115
 
@@ -2,4 +2,4 @@
2
2
  :major: 1
3
3
  :build:
4
4
  :minor: 16
5
- :patch: 1
5
+ :patch: 2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "1.16.1"
8
+ s.version = "1.16.2"
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"]
@@ -136,7 +136,7 @@ class Array
136
136
  #
137
137
  result = []
138
138
 
139
- arg.map!(&Backports.method(:coerce_to_ary))
139
+ arg.map!{|ary| Backports.coerce_to_ary(ary)}
140
140
  arg.reverse! # to get the results in the same order as in MRI, vary the last argument first
141
141
  arg.push self
142
142
 
@@ -5,6 +5,28 @@ class Array
5
5
  delete_if{|elem| !yield elem}
6
6
  end unless method_defined? :keep_if
7
7
 
8
+ if [1].product([2]){break false}
9
+ def product_with_block(*arg, &block)
10
+ return product_without_block(*arg) unless block_given?
11
+ # Same implementation as 1.8.7, but yielding
12
+ arg.map!{|ary| Backports.coerce_to_ary(ary)}
13
+ arg.reverse! # to get the results in the same order as in MRI, vary the last argument first
14
+ arg.push self
15
+
16
+ outer_lambda = arg.inject(block) do |proc, values|
17
+ lambda do |partial|
18
+ values.each do |val|
19
+ proc.call(partial.dup << val)
20
+ end
21
+ end
22
+ end
23
+
24
+ outer_lambda.call([])
25
+ self
26
+ end
27
+ Backports.alias_method_chain self, :product, :block
28
+ end
29
+
8
30
  def rotate(n=1)
9
31
  dup.rotate!(n)
10
32
  end unless method_defined? :rotate
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 16
8
- - 1
9
- version: 1.16.1
8
+ - 2
9
+ version: 1.16.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Marc-Andr\xC3\xA9 Lafortune"