iterable 0.0.10.pre → 0.0.11.pre
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.
- data/lib/array.rb +5 -0
- data/lib/iterable.rb +1 -2
- data/lib/iterable_array.rb +39 -12
- data/lib/iterable_array/iterators.rb +2 -4
- data/lib/iterable_array/special_modifiers_iterating.rb +3 -0
- data/lib/iterable_array/version.rb +1 -1
- data/lib/sampler.rb +11 -0
- data/lib/swapable.rb +3 -5
- metadata +22 -3
data/lib/array.rb
ADDED
data/lib/iterable.rb
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "#{File.expand_path File.dirname(__FILE__)}/iterable_array"
|
data/lib/iterable_array.rb
CHANGED
@@ -5,16 +5,23 @@
|
|
5
5
|
# Or the remix gem, maybe.
|
6
6
|
require 'forwardable'
|
7
7
|
|
8
|
-
|
8
|
+
base_path = File.expand_path File.dirname __FILE__
|
9
|
+
|
10
|
+
require "#{base_path}/iterable_array/version.rb"
|
11
|
+
|
12
|
+
require "#{base_path}/swapable.rb"
|
13
|
+
require "#{base_path}/array.rb"
|
14
|
+
# Required for ruby 1.8 compatibility by IterableArray#shuffle! during iteration
|
15
|
+
require "#{base_path}/sampler.rb" unless [].respond_to? :sample
|
16
|
+
|
17
|
+
require "#{base_path}/iterable_array/special_accessors.rb"
|
18
|
+
require "#{base_path}/iterable_array/iterators.rb"
|
19
|
+
require "#{base_path}/iterable_array/iterator_specials.rb"
|
20
|
+
require "#{base_path}/iterable_array/special_modifiers_noniterating.rb"
|
9
21
|
|
10
|
-
require_relative './swapable.rb'
|
11
|
-
require_relative './iterable_array/special_accessors.rb'
|
12
|
-
require_relative './iterable_array/iterators.rb'
|
13
|
-
require_relative './iterable_array/iterator_specials.rb'
|
14
|
-
require_relative './iterable_array/special_modifiers_noniterating.rb'
|
15
22
|
# The following are not yet modules.
|
16
|
-
|
17
|
-
|
23
|
+
require "#{base_path}/iterable_array/special_modifiers_iterating.rb"
|
24
|
+
require "#{base_path}/iterable_array/plain_modifiers.rb"
|
18
25
|
|
19
26
|
class IterableArray
|
20
27
|
extend Forwardable
|
@@ -32,7 +39,10 @@ class IterableArray
|
|
32
39
|
@@iterator_specials = [ :tracking, :tracking=, :invert_tracking, ]
|
33
40
|
|
34
41
|
@@plain_accessors = [ :frozen?, :==, :[]=, :size, :length, :to_a, :to_s, :to_json, :to_enum, :include?, :hash, :to_ary, :fetch, :inspect, :at, :join, :empty?, :member?, :pack, :shelljoin, ]
|
35
|
-
@@
|
42
|
+
@@plain_accessors.push :choice if Array.new.respond_to? :choice
|
43
|
+
@@plain_accessors.push :nitems if Array.new.respond_to? :nitems
|
44
|
+
@@special_accessors = [ :<<, :concat, :&, :|, :*, :+, :-, :[], :drop, :dup, :compact, :slice, :<=>, :eql?, :indices, :indexes, :values_at, :assoc, :rassoc, :first, :sort, :last, :flatten, :reverse, :shuffle, :push, :replace, :rotate, :swap, :swap_indices, :take, :transpose, :uniq, ]
|
45
|
+
@@special_accessors.push :sample if Array.new.respond_to? :sample
|
36
46
|
|
37
47
|
@@plain_modifiers = [ :delete, :delete_at, ]
|
38
48
|
@@special_modifiers = [ :clear, :compact!, :flatten!, :insert, :move, :move_from, :shift, :shuffle!, :sort!, :sort_by!, :unshift, :pop, :reverse!, :rotate!, :slice!, :swap!, :swap_indices!, :uniq!, ]
|
@@ -72,9 +82,20 @@ class IterableArray
|
|
72
82
|
remove_methods *@@special_modifiers
|
73
83
|
end
|
74
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
85
|
+
if Class.respond_to? :class_exec and Object.respond_to? :singleton_class
|
86
|
+
def remove_methods *ary
|
87
|
+
ary.each do |meth|
|
88
|
+
singleton_class.class_exec { remove_method meth }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
else
|
92
|
+
# Object#singleton_class isn't available in Ruby 1.8
|
93
|
+
# The following Ruby 1.8-compatible version is appreciably
|
94
|
+
# slower in Ruby 1.9 than the version using Object#singleton_class
|
95
|
+
def remove_methods *ary
|
96
|
+
ary.each do |methd|
|
97
|
+
eval "class << self; remove_method :'#{methd}'; end"
|
98
|
+
end
|
78
99
|
end
|
79
100
|
end
|
80
101
|
|
@@ -96,5 +117,11 @@ class IterableArray
|
|
96
117
|
@progenitor = progenitor
|
97
118
|
class << self; undef_method :take_progenitor; end
|
98
119
|
end
|
120
|
+
|
121
|
+
public
|
122
|
+
|
123
|
+
def to_iter
|
124
|
+
self
|
125
|
+
end
|
99
126
|
end
|
100
127
|
|
@@ -44,7 +44,7 @@ class IterableArray
|
|
44
44
|
##################################################
|
45
45
|
starter = args.first
|
46
46
|
the_final = args.at 1
|
47
|
-
ender =
|
47
|
+
ender = lambda { the_final or length }
|
48
48
|
|
49
49
|
#############
|
50
50
|
# Iteration #
|
@@ -404,9 +404,7 @@ class IterableArray
|
|
404
404
|
|
405
405
|
def comb_perm_generator methd, ary, n
|
406
406
|
out = []
|
407
|
-
ary.
|
408
|
-
out << item
|
409
|
-
}) ]
|
407
|
+
ary.send(methd, n) { |item| out << item }
|
410
408
|
out
|
411
409
|
end
|
412
410
|
|
@@ -174,6 +174,9 @@ class IterableArray
|
|
174
174
|
@array.shuffle!
|
175
175
|
|
176
176
|
locations = []
|
177
|
+
# For Ruby 1.8, where Array#sample does not exist
|
178
|
+
locations = Sampler.new [] unless locations.respond_to? :sample
|
179
|
+
|
177
180
|
@array.to_a.each_with_index { |item, location| locations << location if item == current_item }
|
178
181
|
|
179
182
|
center_indices_at locations.sample
|
data/lib/sampler.rb
ADDED
data/lib/swapable.rb
CHANGED
@@ -7,15 +7,13 @@ module Swapable
|
|
7
7
|
def to_a
|
8
8
|
self
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def dup
|
12
12
|
(super).extend Swapable
|
13
13
|
end
|
14
14
|
|
15
|
-
def swap_2_indices!
|
16
|
-
|
17
|
-
self[arg1] = at arg2
|
18
|
-
self[arg2] = temper
|
15
|
+
def swap_2_indices! i1, i2
|
16
|
+
self[i1], self[i2] = self[i2], self[i1]
|
19
17
|
self
|
20
18
|
end
|
21
19
|
protected :swap_2_indices!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iterable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11.pre
|
5
5
|
prerelease: 7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: ! 'Provides the class IterableArray, which implements all of the methods
|
15
31
|
of Array
|
16
32
|
|
@@ -40,7 +56,9 @@ files:
|
|
40
56
|
- lib/iterable_array/iterator_specials.rb
|
41
57
|
- lib/iterable_array/special_modifiers_iterating.rb
|
42
58
|
- lib/iterable_array.rb
|
59
|
+
- lib/array.rb
|
43
60
|
- lib/swapable.rb
|
61
|
+
- lib/sampler.rb
|
44
62
|
- lib/iterable.rb
|
45
63
|
homepage: https://github.com/scooter-dangle/iterable
|
46
64
|
licenses:
|
@@ -68,3 +86,4 @@ signing_key:
|
|
68
86
|
specification_version: 3
|
69
87
|
summary: Provides a fully iterable array object
|
70
88
|
test_files: []
|
89
|
+
has_rdoc:
|