iterable 0.0.6.pre → 0.0.10.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,8 @@
5
5
  # Or the remix gem, maybe.
6
6
  require 'forwardable'
7
7
 
8
+ require_relative './iterable_array/version.rb'
9
+
8
10
  require_relative './swapable.rb'
9
11
  require_relative './iterable_array/special_accessors.rb'
10
12
  require_relative './iterable_array/iterators.rb'
@@ -46,11 +48,11 @@ class IterableArray
46
48
 
47
49
  def initialize *args
48
50
  @array = Array.new(*args).extend Swapable
49
- @progenitor_binding = binding
51
+ @progenitor = self
50
52
  end
51
53
 
52
54
  def bastardize
53
- @array = self.new_with_binding @array
55
+ @array = self.new_with_progenitor @array
54
56
  @tracking = 0.5
55
57
  class << self
56
58
  def_delegators :@array, *@@special_accessors
@@ -80,15 +82,19 @@ class IterableArray
80
82
 
81
83
  # Necessary for allowing nested iteration with modifying iterators (like
82
84
  # :delete_if)
83
- def new_with_binding array
85
+ # TODO - After refactoring to be a reference to the progenitor itself
86
+ # rather than a binding, need to simplify this... overly complex right
87
+ # now for what it does...
88
+ def new_with_progenitor array
84
89
  iter_ary = IterableArray.new array
85
- iter_ary.take_progenitor_binding @progenitor_binding
90
+ iter_ary.take_progenitor @progenitor
86
91
  iter_ary
87
92
  end
88
93
 
89
- def take_progenitor_binding progenitor_binding
90
- @progenitor_binding = progenitor_binding
91
- class << self; undef_method :take_progenitor_binding; end
94
+ # Not sure this method is worth the trouble
95
+ def take_progenitor progenitor
96
+ @progenitor = progenitor
97
+ class << self; undef_method :take_progenitor; end
92
98
  end
93
99
  end
94
100
 
@@ -2,14 +2,10 @@ class IterableArray
2
2
  # module Iterators
3
3
  private
4
4
  def catch_a_break
5
- result = nil
6
- begin
7
- bastardize
8
- result = yield
9
- ensure
10
- debastardize
11
- end
12
- result
5
+ bastardize
6
+ yield
7
+ ensure
8
+ debastardize
13
9
  end
14
10
 
15
11
  def increment_indices
@@ -176,7 +172,7 @@ class IterableArray
176
172
  # iteration levels would not be able to adjust their indices
177
173
  # to account for the change in array size.
178
174
  if yield @array.at(@current_index)
179
- @progenitor_binding.eval "self.delete_at #{@current_index}"
175
+ @progenitor.send :delete_at, @current_index
180
176
  end
181
177
  increment_indices
182
178
  end
@@ -293,27 +289,24 @@ class IterableArray
293
289
  return @array.to_enum(:cycle, n) unless block_given?
294
290
 
295
291
  catch_a_break do
296
- if n.nil?
297
- until @array.empty?
298
- @backward_index, @current_index, @forward_index = -1, 0, 1
299
- while @current_index < @array.size
300
- yield @array.at(@current_index)
301
- increment_indices
302
- end
303
- end
304
- else
305
- n.times do
306
- @backward_index, @current_index, @forward_index = -1, 0, 1
307
- while @current_index < @array.size
308
- yield @array.at(@current_index)
309
- increment_indices
310
- end
292
+ cycle_conditional_helper n do
293
+ @backward_index, @current_index, @forward_index = -1, 0, 1
294
+ while @current_index < @array.size
295
+ yield @array.at(@current_index)
296
+ increment_indices
311
297
  end
312
298
  end
313
299
 
314
300
  nil
315
301
  end
316
302
  end
303
+
304
+ def cycle_conditional_helper n, &block
305
+ n.nil? ?
306
+ (yield until @array.empty?) :
307
+ n.times { yield }
308
+ end
309
+ private :cycle_conditional_helper
317
310
 
318
311
  def index obj = :undefined
319
312
  unless block_given?
@@ -0,0 +1,4 @@
1
+ class IterableArray
2
+ # The version of IterableArray you are using
3
+ VERSION = '0.0.10.pre'
4
+ end
@@ -1,4 +1,5 @@
1
1
  module Swapable
2
+ # to_iter doesn't really belong in Swapable
2
3
  def to_iter
3
4
  IterableArray.new self
4
5
  end
@@ -6,6 +7,10 @@ module Swapable
6
7
  def to_a
7
8
  self
8
9
  end
10
+
11
+ def dup
12
+ (super).extend Swapable
13
+ end
9
14
 
10
15
  def swap_2_indices! arg1, arg2
11
16
  temper = at arg1
@@ -27,11 +32,11 @@ module Swapable
27
32
  alias_method :swap_indexes!, :swap_indices!
28
33
 
29
34
  def swap *args
30
- dup.extend(Swapable).swap! *args
35
+ dup.swap! *args
31
36
  end
32
37
 
33
38
  def swap_indices *args
34
- dup.extend(Swapable).swap_indices! *args
39
+ dup.swap_indices! *args
35
40
  end
36
41
  alias_method :swap_indexes, :swap_indices
37
42
 
metadata CHANGED
@@ -1,31 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iterable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.pre
5
- prerelease: 6
4
+ version: 0.0.10.pre
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Scott L Steele
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ''
14
+ description: ! 'Provides the class IterableArray, which implements all of the methods
15
+ of Array
16
+
17
+ (as of Ruby 1.9.3) in an iterable-aware fashion. I.e., behavior is defined to
18
+
19
+ the greatest extent possible for operations that modify an IterableArray from
20
+
21
+ within an iteration block (e.g. each, map, delete_if, reverse_each). To use,
22
+
23
+ call #to_iter on a pre-existing Array or use IterableArray.new; the
24
+
25
+ IterableArray should act identically to a regular Array except that it
26
+
27
+ responds logically to modifications during iteration.
28
+
29
+ '
15
30
  email: ScottLSteele@gmail.com
16
31
  executables: []
17
32
  extensions: []
18
33
  extra_rdoc_files: []
19
34
  files:
20
- - lib/iterable_array/iterator_specials.rb
35
+ - lib/iterable_array/version.rb
21
36
  - lib/iterable_array/special_modifiers_noniterating.rb
22
- - lib/iterable_array/special_modifiers_iterating.rb
37
+ - lib/iterable_array/iterators.rb
23
38
  - lib/iterable_array/special_accessors.rb
24
39
  - lib/iterable_array/plain_modifiers.rb
25
- - lib/iterable_array/iterators.rb
40
+ - lib/iterable_array/iterator_specials.rb
41
+ - lib/iterable_array/special_modifiers_iterating.rb
42
+ - lib/iterable_array.rb
26
43
  - lib/swapable.rb
27
44
  - lib/iterable.rb
28
- - lib/iterable_array.rb
29
45
  homepage: https://github.com/scooter-dangle/iterable
30
46
  licenses:
31
47
  - ''
@@ -47,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
63
  version: 1.3.1
48
64
  requirements: []
49
65
  rubyforge_project:
50
- rubygems_version: 1.8.10
66
+ rubygems_version: 1.8.23
51
67
  signing_key:
52
68
  specification_version: 3
53
69
  summary: Provides a fully iterable array object
54
70
  test_files: []
55
- has_rdoc: