backports 1.10.0 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 10
4
- :patch: 0
4
+ :patch: 1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "1.10.0"
8
+ s.version = "1.10.1"
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{2009-09-29}
12
+ s.date = %q{2009-10-03}
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}
@@ -1,19 +1,21 @@
1
1
  require 'enumerator'
2
- module Enumerable
3
- class Enumerator
4
- def next
5
- require 'generator'
6
- @generator ||= Generator.new(self)
7
- raise StopIteration unless @generator.next?
8
- @generator.next
9
- end unless method_defined? :next
2
+ if (Enumerable::Enumerator rescue false)
3
+ module Enumerable
4
+ class Enumerator
5
+ def next
6
+ require 'generator'
7
+ @generator ||= Generator.new(self)
8
+ raise StopIteration unless @generator.next?
9
+ @generator.next
10
+ end unless method_defined? :next
10
11
 
11
- def rewind
12
- @object.rewind if @object.respond_to? :rewind
13
- require 'generator'
14
- @generator ||= Generator.new(self)
15
- @generator.rewind
16
- self
17
- end unless method_defined? :rewind
12
+ def rewind
13
+ @object.rewind if @object.respond_to? :rewind
14
+ require 'generator'
15
+ @generator ||= Generator.new(self)
16
+ @generator.rewind
17
+ self
18
+ end unless method_defined? :rewind
19
+ end if const_defined? :Enumerator
18
20
  end
19
21
  end
@@ -7,30 +7,36 @@ module Enumerable
7
7
  end unless method_defined? :each_with_object
8
8
 
9
9
  def chunk(initial_state = nil, &original_block)
10
- Enumerator.new do |yielder|
11
- previous = Backports::Undefined
10
+ raise ArgumentError, "no block given" unless block_given?
11
+ ::Enumerator.new do |yielder|
12
+ previous = nil
12
13
  accumulate = []
13
14
  block = initial_state.nil? ? original_block : Proc.new{|val| original_block.yield(val, initial_state.clone)}
14
15
  each do |val|
15
- case key = block.yield(val)
16
- when nil, :_separator
17
- next
18
- when :_singleton
19
- yielder.yield previous, accumulate unless accumulate.empty?
20
- yielder.yield key, [val]
16
+ key = block.yield(val)
17
+ if key.nil? || (key.is_a?(Symbol) && key.to_s[0,1] == "_")
18
+ yielder.yield [previous, accumulate] unless accumulate.empty?
21
19
  accumulate = []
22
- previous = Backports::Undefined
23
- when previous, Backports::Undefined
24
- accumulate << val
25
- previous = key
20
+ previous = nil
21
+ case key
22
+ when nil, :_separator
23
+ when :_singleton
24
+ yielder.yield [key, [val]]
25
+ else
26
+ raise RuntimeError, "symbol beginning with an underscore are reserved"
27
+ end
26
28
  else
27
- yielder.yield previous, accumulate unless accumulate.empty?
28
- accumulate = [val]
29
+ if previous.nil? || previous == key
30
+ accumulate << val
31
+ else
32
+ yielder.yield [previous, accumulate] unless accumulate.empty?
33
+ accumulate = [val]
34
+ end
29
35
  previous = key
30
36
  end
31
37
  end
32
38
  # what to do in case of a break?
33
- yielder.yield previous, accumulate unless accumulate.empty?
39
+ yielder.yield [previous, accumulate] unless accumulate.empty?
34
40
  end
35
- end
41
+ end unless method_defined? :chunk
36
42
  end
@@ -79,8 +79,8 @@ unless Kernel.method_defined? :respond_to_missing?
79
79
  false
80
80
  end
81
81
 
82
- def respond_to_with_call_to_respond_to_missing? method
83
- respond_to_without_call_to_respond_to_missing?(method) || respond_to_missing?(method)
82
+ def respond_to_with_call_to_respond_to_missing? method, include_priv=false
83
+ respond_to_without_call_to_respond_to_missing?(method, include_priv) || respond_to_missing?(method)
84
84
  end
85
85
  Backports.alias_method_chain self, :respond_to?, :call_to_respond_to_missing
86
86
 
@@ -199,7 +199,30 @@ class EnumerableTest < Test::Unit::TestCase
199
199
  [1, [3,4,5]],
200
200
  [0, [6,7]]], e.to_a
201
201
  end
202
+
203
+ should "should pass two arguments to the block" do
204
+ e = (1..7).chunk{|i| (i/3) % 2}
205
+ e.each do |key, val|
206
+ assert_equal 0, key
207
+ assert_equal [1,2], val
208
+ break
209
+ end
210
+ end
211
+
212
+ should "handles nil & :_symbol" do
213
+ a = [1,1,nil,1,:_separator, 1, :_singleton, 1]
214
+ e = a.size.times.chunk{|i| a[i]}
215
+ assert_equal [
216
+ [1,[0,1]],
217
+ [1,[3]],
218
+ [1,[5]],
219
+ [:_singleton, [6]],
220
+ [1,[7]]
221
+ ], e.to_a
222
+ end
223
+
202
224
  end
225
+
203
226
  context "given an initial_state argument" do
204
227
  should "give a new copy" do
205
228
  a = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-29 00:00:00 -04:00
12
+ date: 2009-10-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15