backports 2.8.1 → 2.8.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.
@@ -7,7 +7,7 @@ if (Enumerable::Enumerator rescue false)
7
7
 
8
8
  def next
9
9
  require 'generator'
10
- @generator ||= Generator.new(self)
10
+ @generator ||= ::Generator.new(self)
11
11
  raise StopIteration unless @generator.next?
12
12
  @generator.next
13
13
  end unless method_defined? :next
@@ -15,10 +15,10 @@ if (Enumerable::Enumerator rescue false)
15
15
  def rewind
16
16
  @object.rewind if @object.respond_to? :rewind
17
17
  require 'generator'
18
- @generator ||= Generator.new(self)
18
+ @generator ||= ::Generator.new(self)
19
19
  @generator.rewind
20
20
  self
21
21
  end unless method_defined? :rewind
22
22
  end if const_defined? :Enumerator
23
23
  end
24
- end
24
+ end
@@ -7,12 +7,7 @@ class Enumerator
7
7
  # A simple class which allows the construction of Enumerator from a block
8
8
  class Yielder
9
9
  def initialize(&block)
10
- @main_block = block
11
- end
12
-
13
- def each(&block)
14
10
  @final_block = block
15
- @main_block.call(self)
16
11
  end
17
12
 
18
13
  def yield(*arg)
@@ -25,12 +20,22 @@ class Enumerator
25
20
  end
26
21
  end
27
22
 
23
+ class Generator
24
+ def initialize(&block)
25
+ @main_block = block
26
+ end
27
+
28
+ def each(&block)
29
+ @main_block.call(Yielder.new(&block))
30
+ end
31
+ end
32
+
28
33
  def initialize_with_optional_block(*arg, &block)
29
34
  return initialize_without_optional_block(*arg, &nil) unless arg.empty? # Ruby 1.9 apparently ignores the block if any argument is present
30
- initialize_without_optional_block(Yielder.new(&block))
35
+ initialize_without_optional_block(Generator.new(&block))
31
36
  end
32
37
  Backports.alias_method_chain self, :initialize, :optional_block
33
38
  end
34
39
 
35
40
  Backports.alias_method self, :with_object, :each_with_object
36
- end
41
+ end
@@ -1,6 +1,6 @@
1
1
  class Array
2
2
  def bsearch
3
- return to_enum __method__ unless block_given?
3
+ return to_enum(__method__) unless block_given?
4
4
  from = 0
5
5
  to = size - 1
6
6
  satisfied = nil
@@ -5,5 +5,5 @@ module Enumerable
5
5
  end
6
6
 
7
7
  class Enumerator
8
- autoload :Lazy, File.expand_path(File.dirname(__FILE__) + "/enumerator/lazy")
8
+ require_relative 'enumerator/lazy' unless const_defined? :Lazy
9
9
  end
@@ -9,7 +9,7 @@ class Enumerator
9
9
  end
10
10
 
11
11
  class Lazy < Enumerator
12
- @@done = Object.new # used internally to bail out of an iteration
12
+ @@done = :__backports_lazy_enumeration_done__ # used internally to bail out of an iteration
13
13
 
14
14
  alias_method :non_lazy_cycle, :cycle # cycle must be handled in a tricky way
15
15
  @@cycler = Struct.new(:object, :n)
@@ -75,7 +75,7 @@ class Enumerator
75
75
  def drop(n)
76
76
  n = Backports::coerce_to_int(n)
77
77
  Lazy.new(self) do |yielder, *values|
78
- data = yielder.backports_memo ||= {remain: n}
78
+ data = yielder.backports_memo ||= {:remain => n}
79
79
  if data[:remain] > 0
80
80
  data[:remain] -= 1
81
81
  else
@@ -87,7 +87,7 @@ class Enumerator
87
87
  def drop_while
88
88
  raise ArgumentError, "tried to call lazy drop_while without a block" unless block_given?
89
89
  Lazy.new(self) do |yielder, *values|
90
- data = yielder.backports_memo ||= {dropping: true}
90
+ data = yielder.backports_memo ||= {:dropping => true}
91
91
  yielder.yield(*values) unless data[:dropping] &&= yield(*values)
92
92
  end
93
93
  end
@@ -97,7 +97,7 @@ class Enumerator
97
97
  raise ArgumentError, 'attempt to take negative size' if n < 0
98
98
  return Lazy.new([]){} if n == 0
99
99
  Lazy.new(self) do |yielder, *values|
100
- data = yielder.backports_memo ||= {remain: n}
100
+ data = yielder.backports_memo ||= {:remain => n}
101
101
  yielder.yield(*values)
102
102
  throw @@done if (data[:remain] -= 1) == 0
103
103
  end
@@ -137,7 +137,7 @@ class Enumerator
137
137
  # Handle trivial case of multiple array arguments separately
138
138
  # by avoiding Enumerator#next for efficiency & compatibility
139
139
  Lazy.new(self) do |yielder, *values|
140
- data = yielder.backports_memo ||= {iter: 0}
140
+ data = yielder.backports_memo ||= {:iter => 0}
141
141
  values = values.first unless values.size > 1
142
142
  yielder << arys.map{|ary| ary[data[:iter]]}.unshift(values)
143
143
  data[:iter] += 1
@@ -1,6 +1,6 @@
1
1
  class Range
2
2
  def bsearch
3
- return to_enum __method__ unless block_given?
3
+ return to_enum(__method__) unless block_given?
4
4
  from = self.begin
5
5
  to = self.end
6
6
  unless from.is_a?(Numeric) && to.is_a?(Numeric)
@@ -9,9 +9,9 @@ class Range
9
9
 
10
10
  midpoint = nil
11
11
  if from.is_a?(Integer) && to.is_a?(Integer)
12
- convert = ->{ midpoint }
12
+ convert = Proc.new{ midpoint }
13
13
  else
14
- map = ->(pk, unpk, nb) do
14
+ map = Proc.new do |pk, unpk, nb|
15
15
  result, = [nb.abs].pack(pk).unpack(unpk)
16
16
  nb < 0 ? -result : result
17
17
  end.curry
@@ -19,7 +19,7 @@ class Range
19
19
  f2i = map['D', 'q']
20
20
  from = f2i[from.to_f]
21
21
  to = f2i[to.to_f]
22
- convert = -> { i2f[midpoint] }
22
+ convert = Proc.new{ i2f[midpoint] }
23
23
  end
24
24
  to -= 1 if exclude_end?
25
25
  satisfied = nil
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "2.8.1"
2
+ VERSION = "2.8.2"
3
3
  end
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: 2.8.1
4
+ version: 2.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: