wwood-reach 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -1
- data/Gemfile +3 -3
- data/README.rdoc +1 -51
- data/Rakefile +1 -9
- data/VERSION +1 -1
- data/wwood-reach.gemspec +17 -20
- metadata +64 -94
- data/lib/reach.rb +0 -113
- data/test/test_reach.rb +0 -92
data/CHANGES
CHANGED
data/Gemfile
CHANGED
@@ -2,12 +2,12 @@ source "http://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'reachable'
|
5
6
|
|
6
7
|
# Add dependencies to develop your gem here.
|
7
8
|
# Include everything needed to run rake, tests, features, etc.
|
8
9
|
group :development do
|
9
10
|
gem "shoulda", ">= 0"
|
10
|
-
gem "bundler", "
|
11
|
-
gem "jeweler", "
|
12
|
-
gem "rcov", ">= 0"
|
11
|
+
gem "bundler", "> 1.0.0"
|
12
|
+
gem "jeweler", "> 1.6.0"
|
13
13
|
end
|
data/README.rdoc
CHANGED
@@ -1,54 +1,4 @@
|
|
1
|
-
Copyright (C) 2008 Ben J Woodcroft <donttrustben somewhere near gmail.com>
|
2
1
|
|
3
|
-
This software is BETA! Use at your own risk.
|
4
2
|
|
5
|
-
= Reach
|
6
3
|
|
7
|
-
|
8
|
-
to methods. For instance, a ReachableArray of Book objects can not only take normal Array methods such as
|
9
|
-
collect and sum, but also methods that operate Book objects, such as author and title.
|
10
|
-
|
11
|
-
== Example
|
12
|
-
|
13
|
-
Say I have an regular ActiveRecord driven database, that has Bookshelf, Book, and Author objects. Bookshelves have many books, and books have many authors.
|
14
|
-
|
15
|
-
Say I want all the books.
|
16
|
-
|
17
|
-
% Book.all
|
18
|
-
|
19
|
-
Then I want to find all the bookshelves from those that contain those books.
|
20
|
-
|
21
|
-
% Book.all.collect{|book| book.bookshelf} => array of bookshelves.
|
22
|
-
|
23
|
-
From personal experience, running a single method on each array element and collecting the results is quite common, especially in Rails. The idea, then, is to make the arrays not just responsive to the methods that apply to the Array itself, but to methods that apply to the +members+ of that array. That is, make the array reachable (caution: made up word). In the case above we want to run the 'bookshelf' method on each of the book objects in the array.
|
24
|
-
|
25
|
-
To make an array reachable, convert it into a ReachableArray object, by calling the reach method of Array, which is added by the inclusion of the reach library.
|
26
|
-
|
27
|
-
% require 'reach'
|
28
|
-
% Book.all.reach => ReachableArray of books
|
29
|
-
|
30
|
-
Now getting the corresponding array of bookshelves requires less typing:
|
31
|
-
|
32
|
-
% require 'reach'
|
33
|
-
% Book.all.reach.bookshelf => ReachableArray of Bookshelf objects
|
34
|
-
|
35
|
-
Notice that a ReachableArray is returned by the bookshelf method, not an Array. This means you can chain reaches together:
|
36
|
-
|
37
|
-
% require 'reach'
|
38
|
-
% Author.all.reach.book.bookshelf => ReachableArray of Bookshelf objects
|
39
|
-
|
40
|
-
Removing reachability from the array, or retracting, is equally as simple - just use the retract method:
|
41
|
-
|
42
|
-
% require 'reach'
|
43
|
-
% Book.all.reach.bookshelf.retract => Array of Bookshelf objects
|
44
|
-
|
45
|
-
=== Slap
|
46
|
-
|
47
|
-
Like reach, the slap method is another method added to the Array class to make it mroe transparent. The difference is that reach looks to see if the given method operates on the Array class, and if not then applies it to each member of that array. The slap method bypasses the first step, and just applies the given method to each member. For instance
|
48
|
-
|
49
|
-
% require 'reach'
|
50
|
-
% [[1,2,3],[4]].slap.length.retract => [1,3]
|
51
|
-
|
52
|
-
== Caution
|
53
|
-
|
54
|
-
When operating on a ReachableArray, methods that operate on the Array itself take precedence over methods that apply to array members.
|
4
|
+
This software has been renamed to reachable, so as not to conflict with another rubygem called reach. The new version is available at http://github.com/wwood/reachable
|
data/Rakefile
CHANGED
@@ -34,17 +34,9 @@ Rake::TestTask.new(:test) do |test|
|
|
34
34
|
test.verbose = true
|
35
35
|
end
|
36
36
|
|
37
|
-
require 'rcov/rcovtask'
|
38
|
-
Rcov::RcovTask.new do |test|
|
39
|
-
test.libs << 'test'
|
40
|
-
test.pattern = 'test/**/test_*.rb'
|
41
|
-
test.verbose = true
|
42
|
-
test.rcov_opts << '--exclude "gems/*"'
|
43
|
-
end
|
44
|
-
|
45
37
|
task :default => :test
|
46
38
|
|
47
|
-
require '
|
39
|
+
require 'rdoc/task'
|
48
40
|
Rake::RDocTask.new do |rdoc|
|
49
41
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
42
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/wwood-reach.gemspec
CHANGED
@@ -4,15 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "wwood-reach"
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben J Woodcroft"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
|
15
|
-
s.email = %q{gmail.com after donttrustben}
|
12
|
+
s.date = "2012-08-13"
|
13
|
+
s.description = "For instance, a ReachableArray of Book objects can not only take normal Array methods such as\ncollect and sum, but also methods that operate Book objects, such as author and title. "
|
14
|
+
s.email = "gmail.com after donttrustben"
|
16
15
|
s.extra_rdoc_files = [
|
17
16
|
"LICENSE.txt",
|
18
17
|
"README.rdoc"
|
@@ -24,37 +23,35 @@ collect and sum, but also methods that operate Book objects, such as author and
|
|
24
23
|
"README.rdoc",
|
25
24
|
"Rakefile",
|
26
25
|
"VERSION",
|
27
|
-
"lib/reach.rb",
|
28
26
|
"rdoc.sh",
|
29
27
|
"reach.gemspec",
|
30
|
-
"test/test_reach.rb",
|
31
28
|
"wwood-reach.gemspec"
|
32
29
|
]
|
33
|
-
s.homepage =
|
30
|
+
s.homepage = "http://github.com/wwood/reach"
|
34
31
|
s.licenses = ["MIT"]
|
35
32
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version =
|
37
|
-
s.summary =
|
33
|
+
s.rubygems_version = "1.8.17"
|
34
|
+
s.summary = "Reach is a small Ruby liby that extends the Array class so that Arrays are more transparent to methods."
|
38
35
|
|
39
36
|
if s.respond_to? :specification_version then
|
40
37
|
s.specification_version = 3
|
41
38
|
|
42
39
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_runtime_dependency(%q<reachable>, [">= 0"])
|
43
41
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
44
|
-
s.add_development_dependency(%q<bundler>, ["
|
45
|
-
s.add_development_dependency(%q<jeweler>, ["
|
46
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
42
|
+
s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
|
43
|
+
s.add_development_dependency(%q<jeweler>, ["> 1.6.0"])
|
47
44
|
else
|
45
|
+
s.add_dependency(%q<reachable>, [">= 0"])
|
48
46
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
49
|
-
s.add_dependency(%q<bundler>, ["
|
50
|
-
s.add_dependency(%q<jeweler>, ["
|
51
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
47
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
48
|
+
s.add_dependency(%q<jeweler>, ["> 1.6.0"])
|
52
49
|
end
|
53
50
|
else
|
51
|
+
s.add_dependency(%q<reachable>, [">= 0"])
|
54
52
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
55
|
-
s.add_dependency(%q<bundler>, ["
|
56
|
-
s.add_dependency(%q<jeweler>, ["
|
57
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
53
|
+
s.add_dependency(%q<bundler>, ["> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["> 1.6.0"])
|
58
55
|
end
|
59
56
|
end
|
60
57
|
|
metadata
CHANGED
@@ -1,138 +1,108 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: wwood-reach
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 2
|
10
|
-
version: 0.2.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Ben J Woodcroft
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
type: :development
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: reachable
|
16
|
+
requirement: &81713150 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 0
|
31
|
-
version: "0"
|
32
|
-
name: shoulda
|
33
|
-
version_requirements: *id001
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
34
23
|
prerelease: false
|
35
|
-
|
24
|
+
version_requirements: *81713150
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: shoulda
|
27
|
+
requirement: &81712910 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
36
33
|
type: :development
|
37
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *81712910
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &81712670 !ruby/object:Gem::Requirement
|
38
39
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 23
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 0
|
46
|
-
- 0
|
40
|
+
requirements:
|
41
|
+
- - ! '>'
|
42
|
+
- !ruby/object:Gem::Version
|
47
43
|
version: 1.0.0
|
48
|
-
name: bundler
|
49
|
-
version_requirements: *id002
|
50
|
-
prerelease: false
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
44
|
type: :development
|
53
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *81712670
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &81712430 !ruby/object:Gem::Requirement
|
54
50
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
hash: 15
|
59
|
-
segments:
|
60
|
-
- 1
|
61
|
-
- 6
|
62
|
-
- 0
|
51
|
+
requirements:
|
52
|
+
- - ! '>'
|
53
|
+
- !ruby/object:Gem::Version
|
63
54
|
version: 1.6.0
|
64
|
-
name: jeweler
|
65
|
-
version_requirements: *id003
|
66
|
-
prerelease: false
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
55
|
type: :development
|
69
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 3
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
version: "0"
|
78
|
-
name: rcov
|
79
|
-
version_requirements: *id004
|
80
56
|
prerelease: false
|
81
|
-
|
82
|
-
|
57
|
+
version_requirements: *81712430
|
58
|
+
description: ! 'For instance, a ReachableArray of Book objects can not only take normal
|
59
|
+
Array methods such as
|
60
|
+
|
61
|
+
collect and sum, but also methods that operate Book objects, such as author and
|
62
|
+
title. '
|
83
63
|
email: gmail.com after donttrustben
|
84
64
|
executables: []
|
85
|
-
|
86
65
|
extensions: []
|
87
|
-
|
88
|
-
extra_rdoc_files:
|
66
|
+
extra_rdoc_files:
|
89
67
|
- LICENSE.txt
|
90
68
|
- README.rdoc
|
91
|
-
files:
|
69
|
+
files:
|
92
70
|
- CHANGES
|
93
71
|
- Gemfile
|
94
72
|
- LICENSE.txt
|
95
73
|
- README.rdoc
|
96
74
|
- Rakefile
|
97
75
|
- VERSION
|
98
|
-
- lib/reach.rb
|
99
76
|
- rdoc.sh
|
100
77
|
- reach.gemspec
|
101
|
-
- test/test_reach.rb
|
102
78
|
- wwood-reach.gemspec
|
103
|
-
has_rdoc: true
|
104
79
|
homepage: http://github.com/wwood/reach
|
105
|
-
licenses:
|
80
|
+
licenses:
|
106
81
|
- MIT
|
107
82
|
post_install_message:
|
108
83
|
rdoc_options: []
|
109
|
-
|
110
|
-
require_paths:
|
84
|
+
require_paths:
|
111
85
|
- lib
|
112
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
87
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
|
118
|
-
segments:
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
119
93
|
- 0
|
120
|
-
|
121
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
hash: 132076431
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
96
|
none: false
|
123
|
-
requirements:
|
124
|
-
- -
|
125
|
-
- !ruby/object:Gem::Version
|
126
|
-
|
127
|
-
segments:
|
128
|
-
- 0
|
129
|
-
version: "0"
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
130
101
|
requirements: []
|
131
|
-
|
132
102
|
rubyforge_project:
|
133
|
-
rubygems_version: 1.
|
103
|
+
rubygems_version: 1.8.17
|
134
104
|
signing_key:
|
135
105
|
specification_version: 3
|
136
|
-
summary: Reach is a small Ruby liby that extends the Array class so that Arrays are
|
106
|
+
summary: Reach is a small Ruby liby that extends the Array class so that Arrays are
|
107
|
+
more transparent to methods.
|
137
108
|
test_files: []
|
138
|
-
|
data/lib/reach.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Ben Woodcroft <donttrustben somewhere near gmail.com>
|
2
|
-
#
|
3
|
-
# This program is free software.
|
4
|
-
# You can distribute/modify this program under the terms of
|
5
|
-
# the GNU General Public License version 3.
|
6
|
-
|
7
|
-
# The point of this is that the
|
8
|
-
# Bookshelf.all.reach.books.each do {|book| puts book.name}
|
9
|
-
# instead of
|
10
|
-
# Bookshelf.all.each do |bookshelf|
|
11
|
-
# bookshelf.books.each do |book|
|
12
|
-
# puts book.name
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
|
16
|
-
# Bookshelf.all.reach is a ReachableArray
|
17
|
-
# the books is an array (bookshelves) of arrays (books)
|
18
|
-
class Array
|
19
|
-
def reach
|
20
|
-
ReachingArray.new(self)
|
21
|
-
end
|
22
|
-
|
23
|
-
def slap
|
24
|
-
SlappingArray.new(self)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class ReachingArray
|
29
|
-
# The array that this reaching array is extending. This might
|
30
|
-
# be a real Array, or a ReachingArray
|
31
|
-
attr_accessor :retract
|
32
|
-
|
33
|
-
def initialize(retract)
|
34
|
-
@retract = retract
|
35
|
-
end
|
36
|
-
|
37
|
-
# The method could be missing from the array, the members, or both.
|
38
|
-
# Try to pass the method to each, in that order, accepting the first taker
|
39
|
-
def method_missing(method, *args, &block)
|
40
|
-
if @retract.respond_to?(method)
|
41
|
-
# If this is an array method, just use that
|
42
|
-
r = @retract.send(method, *args, &block)
|
43
|
-
return r
|
44
|
-
else
|
45
|
-
# If this is an object-specific method, run an each on it.
|
46
|
-
# A simple each won't work because that doesn't modify the
|
47
|
-
# array elements in place as we want, so have to use collect
|
48
|
-
# instead.
|
49
|
-
@retract = @retract.collect do |o|
|
50
|
-
unless o.kind_of?(Array)
|
51
|
-
o.send(method, *args, &block)
|
52
|
-
else
|
53
|
-
# Update in 0.2.1: If the element of the array is an array
|
54
|
-
# itself, then operate on it as a ReachingArray as well.
|
55
|
-
o.reach.send(method, *args, &block).retract
|
56
|
-
end
|
57
|
-
end
|
58
|
-
return self
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Equality test - equality of the underlying retract
|
63
|
-
# arrays is all that matter
|
64
|
-
def ==(another)
|
65
|
-
@retract <=> another.retract
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_s
|
69
|
-
method_missing(:to_s)
|
70
|
-
end
|
71
|
-
|
72
|
-
def slap
|
73
|
-
retract.slap
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class SlappingArray
|
78
|
-
# The array that this reaching array is extending. This might
|
79
|
-
# be a real Array, or a ReachingArray
|
80
|
-
attr_accessor :retract
|
81
|
-
|
82
|
-
def initialize(retract)
|
83
|
-
@retract = retract
|
84
|
-
end
|
85
|
-
|
86
|
-
# Try to pass the method to each of the array members
|
87
|
-
def method_missing(method, *args, &block)
|
88
|
-
@retract = @retract.collect do |o|
|
89
|
-
unless o.kind_of?(Array)
|
90
|
-
o.send(method, *args, &block)
|
91
|
-
else
|
92
|
-
# Update in 0.2.1: If the element of the array is an array
|
93
|
-
# itself, then operate on it as a ReachingArray as well.
|
94
|
-
o.slap.send(method, *args, &block).retract
|
95
|
-
end
|
96
|
-
end
|
97
|
-
return self
|
98
|
-
end
|
99
|
-
|
100
|
-
# Equality test - equality of the underlying retract
|
101
|
-
# arrays is all that matter
|
102
|
-
def ==(another)
|
103
|
-
@retract <=> another.retract
|
104
|
-
end
|
105
|
-
|
106
|
-
def to_s
|
107
|
-
method_missing(:to_s)
|
108
|
-
end
|
109
|
-
|
110
|
-
def reach
|
111
|
-
retract.reach
|
112
|
-
end
|
113
|
-
end
|
data/test/test_reach.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Ben Woodcroft <donttrustben somewhere near gmail.com>
|
2
|
-
#
|
3
|
-
# This program is free software.
|
4
|
-
# You can distribute/modify this program under the terms of
|
5
|
-
# the GNU Lesser General Public License version 3.
|
6
|
-
|
7
|
-
|
8
|
-
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'reach'
|
12
|
-
|
13
|
-
class ReachTest < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@one_level = %w(a b c)
|
16
|
-
@two_level = [[1,2,3],[5]]
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_normality
|
20
|
-
# Test arrays seem normal - this is kinda pointless I would say
|
21
|
-
index = 0
|
22
|
-
@one_level.each { |n|
|
23
|
-
assert_equal @one_level[index], n
|
24
|
-
index += 1
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_simple_method
|
29
|
-
out = @one_level.reach.succ!
|
30
|
-
assert_kind_of ReachingArray, out
|
31
|
-
assert_equal ReachingArray.new(%w(b c d)), out
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_scoping_one
|
35
|
-
assert_equal ReachingArray.new(%w(c d e)), @one_level.reach.succ!.succ!
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_collect
|
39
|
-
assert_equal %w(b c d), @one_level.reach.collect{|c| c.succ}
|
40
|
-
end
|
41
|
-
|
42
|
-
# Catches if the array elements are not modified within the reach
|
43
|
-
def test_double_scope
|
44
|
-
# make sure my assumptions are correct about the
|
45
|
-
# classes being tested
|
46
|
-
assert 1.respond_to?(:zero?)
|
47
|
-
assert_equal false, '1'.respond_to?(:zero?)
|
48
|
-
|
49
|
-
# make sure that the array elements are being reversed
|
50
|
-
str = ['0','2','3']
|
51
|
-
assert_equal [0,2,3], str.reach.to_i.retract
|
52
|
-
assert_equal [true, false, false], str.reach.to_i.zero?.retract
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_block_accepted
|
56
|
-
assert_equal %w(d e f), @one_level.reach.succ.collect{|c| c.succ.succ}
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_to_s
|
60
|
-
assert_equal [1,2].to_s, [1,2].reach.to_s
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_recursive
|
64
|
-
assert_equal [1,[2,3],[[5]]],
|
65
|
-
['1',['2','3'],[['5']]].reach.to_i.retract
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class SlapTest < Test::Unit::TestCase
|
70
|
-
def setup
|
71
|
-
@one_level = %w(a b c)
|
72
|
-
@two_level = [[1,2,3],[5]]
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_simple
|
76
|
-
assert_kind_of SlappingArray, @two_level.slap
|
77
|
-
|
78
|
-
assert_equal [['1','2','3'],['5']], @two_level.slap.to_s.retract
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_mutate
|
82
|
-
assert_kind_of ReachingArray, @two_level.slap.reach
|
83
|
-
assert_equal [[1,2,3],[5]], @two_level.slap.reach.retract
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_array_method_fail
|
87
|
-
assert_raise NoMethodError do
|
88
|
-
@one_level.slap.join(' ')
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|