cartesian 0.5.0 → 0.5.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.
- data/History.txt +8 -1
- data/Manifest.txt +42 -0
- data/README.rdoc +3 -6
- data/lib/cartesian.rb +11 -9
- data/lib/cartesian/version.rb +7 -1
- data/lib/recursive.rb +2 -0
- data/script/txt2html +82 -0
- data/website/doc/classes/Array.html +128 -0
- data/website/doc/classes/Cartesian.html +398 -0
- data/website/doc/classes/Cartesian.src/M000020.html +18 -0
- data/website/doc/classes/Cartesian.src/M000021.html +18 -0
- data/website/doc/classes/Cartesian.src/M000022.html +18 -0
- data/website/doc/classes/Cartesian.src/M000023.html +23 -0
- data/website/doc/classes/Cartesian.src/M000026.html +23 -0
- data/website/doc/classes/Cartesian.src/M000027.html +30 -0
- data/website/doc/classes/CartesianIterator.html +326 -0
- data/website/doc/classes/CartesianIterator.src/M000001.html +21 -0
- data/website/doc/classes/CartesianIterator.src/M000002.html +18 -0
- data/website/doc/classes/CartesianIterator.src/M000003.html +21 -0
- data/website/doc/classes/CartesianIterator.src/M000005.html +20 -0
- data/website/doc/classes/CartesianIterator.src/M000008.html +20 -0
- data/website/doc/classes/CartesianIterator.src/M000009.html +19 -0
- data/website/doc/classes/CartesianIterator.src/M000012.html +19 -0
- data/website/doc/classes/CartesianIterator.src/M000013.html +39 -0
- data/website/doc/classes/Enumerable.html +112 -0
- data/website/doc/classes/GridSearch.html +160 -0
- data/website/doc/classes/GridSearch.src/M000014.html +18 -0
- data/website/doc/classes/GridSearch.src/M000015.html +18 -0
- data/website/doc/classes/Iterable.html +176 -0
- data/website/doc/classes/Iterable.src/M000016.html +19 -0
- data/website/doc/classes/Iterable.src/M000017.html +19 -0
- data/website/doc/classes/Iterable.src/M000018.html +18 -0
- data/website/doc/classes/Iterable.src/M000019.html +18 -0
- data/website/doc/classes/Range.html +118 -0
- data/website/doc/created.rid +1 -0
- data/website/doc/files/cartesian_iterator_rb.html +101 -0
- data/website/doc/files/cartesian_rb.html +108 -0
- data/website/doc/files/grid_search_rb.html +101 -0
- data/website/doc/fr_class_index.html +33 -0
- data/website/doc/fr_file_index.html +29 -0
- data/website/doc/fr_method_index.html +54 -0
- data/website/doc/index.html +24 -0
- data/website/doc/rdoc-style.css +208 -0
- data/website/index.html +110 -0
- data/website/index.txt +96 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.html.erb +48 -0
- metadata +48 -5
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 0.5.1 2011-01-04
|
2
|
+
|
3
|
+
* 1 minor enhancements:
|
4
|
+
* code comment/documentation update
|
5
|
+
* README update
|
6
|
+
* website created (textile index)
|
7
|
+
|
1
8
|
=== 0.5.0 2011-01-03
|
2
9
|
|
3
10
|
* 1 major enhancements:
|
@@ -28,7 +35,7 @@
|
|
28
35
|
=== 0.2.3 13-01-2007 20:50
|
29
36
|
|
30
37
|
* 1 minor enhancement:
|
31
|
-
* power! (aliased as
|
38
|
+
* power! (aliased as '**') method added
|
32
39
|
|
33
40
|
=== 0.2.1 13-01-2007 01:44
|
34
41
|
|
data/Manifest.txt
CHANGED
@@ -15,6 +15,7 @@ lib/recursive.rb
|
|
15
15
|
script/console
|
16
16
|
script/destroy
|
17
17
|
script/generate
|
18
|
+
script/txt2html
|
18
19
|
test/benchmark.rb
|
19
20
|
test/extensions.rb
|
20
21
|
test/test_cartesian.rb
|
@@ -23,3 +24,44 @@ test/test_extensions.rb
|
|
23
24
|
test/test_grid_search.rb
|
24
25
|
test/test_helper.rb
|
25
26
|
test/test_suite.rb
|
27
|
+
website/doc/classes/Array.html
|
28
|
+
website/doc/classes/Cartesian.html
|
29
|
+
website/doc/classes/Cartesian.src/M000020.html
|
30
|
+
website/doc/classes/Cartesian.src/M000021.html
|
31
|
+
website/doc/classes/Cartesian.src/M000022.html
|
32
|
+
website/doc/classes/Cartesian.src/M000023.html
|
33
|
+
website/doc/classes/Cartesian.src/M000026.html
|
34
|
+
website/doc/classes/Cartesian.src/M000027.html
|
35
|
+
website/doc/classes/CartesianIterator.html
|
36
|
+
website/doc/classes/CartesianIterator.src/M000001.html
|
37
|
+
website/doc/classes/CartesianIterator.src/M000002.html
|
38
|
+
website/doc/classes/CartesianIterator.src/M000003.html
|
39
|
+
website/doc/classes/CartesianIterator.src/M000005.html
|
40
|
+
website/doc/classes/CartesianIterator.src/M000008.html
|
41
|
+
website/doc/classes/CartesianIterator.src/M000009.html
|
42
|
+
website/doc/classes/CartesianIterator.src/M000012.html
|
43
|
+
website/doc/classes/CartesianIterator.src/M000013.html
|
44
|
+
website/doc/classes/Enumerable.html
|
45
|
+
website/doc/classes/GridSearch.html
|
46
|
+
website/doc/classes/GridSearch.src/M000014.html
|
47
|
+
website/doc/classes/GridSearch.src/M000015.html
|
48
|
+
website/doc/classes/Iterable.html
|
49
|
+
website/doc/classes/Iterable.src/M000016.html
|
50
|
+
website/doc/classes/Iterable.src/M000017.html
|
51
|
+
website/doc/classes/Iterable.src/M000018.html
|
52
|
+
website/doc/classes/Iterable.src/M000019.html
|
53
|
+
website/doc/classes/Range.html
|
54
|
+
website/doc/created.rid
|
55
|
+
website/doc/files/cartesian_iterator_rb.html
|
56
|
+
website/doc/files/cartesian_rb.html
|
57
|
+
website/doc/files/grid_search_rb.html
|
58
|
+
website/doc/fr_class_index.html
|
59
|
+
website/doc/fr_file_index.html
|
60
|
+
website/doc/fr_method_index.html
|
61
|
+
website/doc/index.html
|
62
|
+
website/doc/rdoc-style.css
|
63
|
+
website/index.html
|
64
|
+
website/index.txt
|
65
|
+
website/javascripts/rounded_corners_lite.inc.js
|
66
|
+
website/stylesheets/screen.css
|
67
|
+
website/template.html.erb
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= cartesian
|
2
2
|
|
3
|
-
* http://github.com/
|
3
|
+
* http://adrianomitre.github.com/cartesian/website/index.html
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
@@ -25,13 +25,10 @@ One can use the Cartesian module directly
|
|
25
25
|
bar = ["a", "b"]
|
26
26
|
Cartesian::product(foo, bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
27
27
|
|
28
|
-
or use the methods provided by the mixin in the Array
|
29
|
-
require 'cartesian'
|
30
|
-
foo = [1, 2]
|
31
|
-
bar = ["a", "b"]
|
28
|
+
or use the methods provided by the mixin in the Array class
|
32
29
|
foo.cartesian(bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
33
30
|
|
34
|
-
which include the short
|
31
|
+
which include the short'n'sweet _x_ method
|
35
32
|
v = [] #=> []
|
36
33
|
for a,b in [1,2].x [3,4]
|
37
34
|
v << [a,b]
|
data/lib/cartesian.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'cartesian_iterator'
|
5
|
+
|
6
|
+
# The Cartesian module provide methods for the calculation
|
3
7
|
# of the cartesian producted between two enumerable objects.
|
4
8
|
#
|
5
9
|
# It can also be easily mixed in into any enumerable class,
|
@@ -30,15 +34,12 @@
|
|
30
34
|
# bar = ["a", "b"]
|
31
35
|
# foo.cartesian(bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
32
36
|
#
|
33
|
-
|
34
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
35
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
36
|
-
|
37
|
-
require 'cartesian_iterator'
|
38
|
-
|
39
37
|
module Cartesian
|
40
38
|
|
41
|
-
|
39
|
+
# Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
|
40
|
+
# due to a mix of newgem versions, each requiring a different one. Not DRY :P
|
41
|
+
#
|
42
|
+
VERSION = "0.5.2"
|
42
43
|
|
43
44
|
# Produces the cartesian product of self and other.
|
44
45
|
# The result is an array of pairs (i.e. two-element arrays).
|
@@ -164,3 +165,4 @@ end
|
|
164
165
|
class Range
|
165
166
|
include Cartesian
|
166
167
|
end
|
168
|
+
|
data/lib/cartesian/version.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
module Cartesian #:nodoc:
|
2
|
+
|
3
|
+
# Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
|
4
|
+
# due to a mix of newgem versions, each requiring a different one. Not DRY :P
|
5
|
+
#
|
2
6
|
module VERSION #:nodoc:
|
3
7
|
MAJOR = 0
|
4
8
|
MINOR = 5
|
5
|
-
TINY =
|
9
|
+
TINY = 2
|
6
10
|
|
7
11
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
8
12
|
end
|
13
|
+
|
9
14
|
end
|
15
|
+
|
data/lib/recursive.rb
CHANGED
data/script/txt2html
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
GEM_NAME = 'cartesian' # what ppl will type to install your gem
|
4
|
+
RUBYFORGE_PROJECT = 'cartesian'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'newgem'
|
9
|
+
require 'rubyforge'
|
10
|
+
rescue LoadError
|
11
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
12
|
+
puts "Install: gem install newgem\n\n"
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
require 'redcloth'
|
16
|
+
require 'syntax/convertors/html'
|
17
|
+
require 'erb'
|
18
|
+
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
19
|
+
|
20
|
+
version = Cartesian::VERSION::STRING
|
21
|
+
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
22
|
+
|
23
|
+
def rubyforge_project_id
|
24
|
+
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
25
|
+
end
|
26
|
+
|
27
|
+
class Fixnum
|
28
|
+
def ordinal
|
29
|
+
# teens
|
30
|
+
return 'th' if (10..19).include?(self % 100)
|
31
|
+
# others
|
32
|
+
case self % 10
|
33
|
+
when 1: return 'st'
|
34
|
+
when 2: return 'nd'
|
35
|
+
when 3: return 'rd'
|
36
|
+
else return 'th'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Time
|
42
|
+
def pretty
|
43
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert_syntax(syntax, source)
|
48
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
49
|
+
end
|
50
|
+
|
51
|
+
if ARGV.length >= 1
|
52
|
+
src, template = ARGV
|
53
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
54
|
+
else
|
55
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
56
|
+
exit!
|
57
|
+
end
|
58
|
+
|
59
|
+
template = ERB.new(File.open(template).read)
|
60
|
+
|
61
|
+
title = nil
|
62
|
+
body = nil
|
63
|
+
File.open(src) do |fsrc|
|
64
|
+
title_text = fsrc.readline
|
65
|
+
body_text_template = fsrc.read
|
66
|
+
body_text = ERB.new(body_text_template).result(binding)
|
67
|
+
syntax_items = []
|
68
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
69
|
+
ident = syntax_items.length
|
70
|
+
element, syntax, source = $1, $2, $3
|
71
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
72
|
+
"syntax-temp-#{ident}"
|
73
|
+
}
|
74
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
75
|
+
body = RedCloth.new(body_text).to_html
|
76
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
77
|
+
end
|
78
|
+
stat = File.stat(src)
|
79
|
+
created = stat.ctime
|
80
|
+
modified = stat.mtime
|
81
|
+
|
82
|
+
$stdout << template.result(binding)
|
@@ -0,0 +1,128 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Array</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Array</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/cartesian_rb.html">
|
59
|
+
cartesian.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/cartesian_iterator_rb.html">
|
63
|
+
cartesian_iterator.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
<a href="../files/grid_search_rb.html">
|
67
|
+
grid_search.rb
|
68
|
+
</a>
|
69
|
+
<br />
|
70
|
+
</td>
|
71
|
+
</tr>
|
72
|
+
|
73
|
+
<tr class="top-aligned-row">
|
74
|
+
<td><strong>Parent:</strong></td>
|
75
|
+
<td>
|
76
|
+
Object
|
77
|
+
</td>
|
78
|
+
</tr>
|
79
|
+
</table>
|
80
|
+
</div>
|
81
|
+
<!-- banner header -->
|
82
|
+
|
83
|
+
<div id="bodyContent">
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
<div id="contextContent">
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
|
97
|
+
<!-- if includes -->
|
98
|
+
<div id="includes">
|
99
|
+
<h3 class="section-bar">Included Modules</h3>
|
100
|
+
|
101
|
+
<div id="includes-list">
|
102
|
+
<span class="include-name"><a href="Cartesian.html">Cartesian</a></span>
|
103
|
+
<span class="include-name"><a href="Iterable.html">Iterable</a></span>
|
104
|
+
<span class="include-name"><a href="GridSearch.html">GridSearch</a></span>
|
105
|
+
</div>
|
106
|
+
</div>
|
107
|
+
|
108
|
+
<div id="section">
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
<!-- if method_list -->
|
118
|
+
|
119
|
+
|
120
|
+
</div>
|
121
|
+
|
122
|
+
|
123
|
+
<div id="validator-badges">
|
124
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
125
|
+
</div>
|
126
|
+
|
127
|
+
</body>
|
128
|
+
</html>
|
@@ -0,0 +1,398 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Cartesian</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Cartesian</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/cartesian_rb.html">
|
59
|
+
cartesian.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
<div id="description">
|
76
|
+
<p>
|
77
|
+
The <a href="Cartesian.html">Cartesian</a> module provide methods for the
|
78
|
+
calculation of the <a href="Cartesian.html#M000024">cartesian</a> producted
|
79
|
+
between two enumerable objects.
|
80
|
+
</p>
|
81
|
+
<p>
|
82
|
+
It can also be easily mixed in into any enumerable class, i.e. any class
|
83
|
+
with <a href="Enumerable.html">Enumerable</a> module mixed in. Notice that
|
84
|
+
the names of the methods for mixin are different.
|
85
|
+
</p>
|
86
|
+
<p>
|
87
|
+
Module:
|
88
|
+
</p>
|
89
|
+
<pre>
|
90
|
+
Cartesian::product(foo, bar)
|
91
|
+
</pre>
|
92
|
+
<p>
|
93
|
+
Mixin:
|
94
|
+
</p>
|
95
|
+
<pre>
|
96
|
+
foo.cartesian( bar )
|
97
|
+
</pre>
|
98
|
+
<p>
|
99
|
+
The module is automatically mixed in <a href="Array.html">Array</a> class.
|
100
|
+
</p>
|
101
|
+
<h2>Author</h2>
|
102
|
+
<p>
|
103
|
+
Adriano MITRE <adriano.mitre@gmail.com>
|
104
|
+
</p>
|
105
|
+
<h2>Example</h2>
|
106
|
+
<p>
|
107
|
+
as module
|
108
|
+
</p>
|
109
|
+
<pre>
|
110
|
+
require 'cartesian'
|
111
|
+
foo = [1, 2]
|
112
|
+
bar = ["a", "b"]
|
113
|
+
Cartesian::product(foo, bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
114
|
+
</pre>
|
115
|
+
<p>
|
116
|
+
as mixin
|
117
|
+
</p>
|
118
|
+
<pre>
|
119
|
+
require 'cartesian'
|
120
|
+
foo = [1, 2]
|
121
|
+
bar = ["a", "b"]
|
122
|
+
foo.cartesian(bar) #=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
|
123
|
+
</pre>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
|
128
|
+
</div>
|
129
|
+
|
130
|
+
<div id="method-list">
|
131
|
+
<h3 class="section-bar">Methods</h3>
|
132
|
+
|
133
|
+
<div class="name-list">
|
134
|
+
<a href="#M000027">**</a>
|
135
|
+
<a href="#M000024">cartesian</a>
|
136
|
+
<a href="#M000022">joined_cartesian</a>
|
137
|
+
<a href="#M000021">joined_product</a>
|
138
|
+
<a href="#M000026">left_product</a>
|
139
|
+
<a href="#M000028">power!</a>
|
140
|
+
<a href="#M000020">product</a>
|
141
|
+
<a href="#M000025">right_product</a>
|
142
|
+
<a href="#M000023">x</a>
|
143
|
+
</div>
|
144
|
+
</div>
|
145
|
+
|
146
|
+
</div>
|
147
|
+
|
148
|
+
|
149
|
+
<!-- if includes -->
|
150
|
+
|
151
|
+
<div id="section">
|
152
|
+
|
153
|
+
|
154
|
+
<div id="constants-list">
|
155
|
+
<h3 class="section-bar">Constants</h3>
|
156
|
+
|
157
|
+
<div class="name-list">
|
158
|
+
<table summary="Constants">
|
159
|
+
<tr class="top-aligned-row context-row">
|
160
|
+
<td class="context-item-name">VERSION</td>
|
161
|
+
<td>=</td>
|
162
|
+
<td class="context-item-value">'0.5.0'</td>
|
163
|
+
</tr>
|
164
|
+
</table>
|
165
|
+
</div>
|
166
|
+
</div>
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<!-- if method_list -->
|
174
|
+
<div id="methods">
|
175
|
+
<h3 class="section-bar">Public Class methods</h3>
|
176
|
+
|
177
|
+
<div id="method-M000021" class="method-detail">
|
178
|
+
<a name="M000021"></a>
|
179
|
+
|
180
|
+
<div class="method-heading">
|
181
|
+
<a href="Cartesian.src/M000021.html" target="Code" class="method-signature"
|
182
|
+
onclick="popupCode('Cartesian.src/M000021.html');return false;">
|
183
|
+
<span class="method-name">joined_product</span><span class="method-args">(first, second)</span>
|
184
|
+
</a>
|
185
|
+
</div>
|
186
|
+
|
187
|
+
<div class="method-description">
|
188
|
+
<p>
|
189
|
+
Behaves as <a href="Cartesian.html#M000020">product</a>, except for the
|
190
|
+
elements are joined.
|
191
|
+
</p>
|
192
|
+
<pre>
|
193
|
+
Cartesian::joined_cartesian( [1,2], %w(A B) ) #=> ["1A", "1B", "2A", "2B"]
|
194
|
+
</pre>
|
195
|
+
<p>
|
196
|
+
or, if mixed in into <a href="Array.html">Array</a>,
|
197
|
+
</p>
|
198
|
+
<pre>
|
199
|
+
[1,2].joined_cartesian %w(A B) #=> ["1A", "1B", "2A", "2B"]
|
200
|
+
</pre>
|
201
|
+
</div>
|
202
|
+
</div>
|
203
|
+
|
204
|
+
<div id="method-M000020" class="method-detail">
|
205
|
+
<a name="M000020"></a>
|
206
|
+
|
207
|
+
<div class="method-heading">
|
208
|
+
<a href="Cartesian.src/M000020.html" target="Code" class="method-signature"
|
209
|
+
onclick="popupCode('Cartesian.src/M000020.html');return false;">
|
210
|
+
<span class="method-name">product</span><span class="method-args">(first, second)</span>
|
211
|
+
</a>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
<div class="method-description">
|
215
|
+
<p>
|
216
|
+
Produces the <a href="Cartesian.html#M000024">cartesian</a> <a
|
217
|
+
href="Cartesian.html#M000020">product</a> of self and other. The result is
|
218
|
+
an array of pairs (i.e. two-element arrays).
|
219
|
+
</p>
|
220
|
+
<pre>
|
221
|
+
Cartesian::product( [1,2], %w(A B) ) #=> [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
|
222
|
+
</pre>
|
223
|
+
<p>
|
224
|
+
or, if mixed in into <a href="Array.html">Array</a>,
|
225
|
+
</p>
|
226
|
+
<pre>
|
227
|
+
[1,2].cartesian %w(A B) #=> [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
|
228
|
+
</pre>
|
229
|
+
</div>
|
230
|
+
</div>
|
231
|
+
|
232
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
233
|
+
|
234
|
+
<div id="method-M000027" class="method-detail">
|
235
|
+
<a name="M000027"></a>
|
236
|
+
|
237
|
+
<div class="method-heading">
|
238
|
+
<a href="Cartesian.src/M000027.html" target="Code" class="method-signature"
|
239
|
+
onclick="popupCode('Cartesian.src/M000027.html');return false;">
|
240
|
+
<span class="method-name">**</span><span class="method-args">(fixnum)</span>
|
241
|
+
</a>
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div class="method-description">
|
245
|
+
<p>
|
246
|
+
Concise way of iterating multi-dimensionally over the same array or range.
|
247
|
+
</p>
|
248
|
+
<p>
|
249
|
+
For instance,
|
250
|
+
</p>
|
251
|
+
<pre>
|
252
|
+
for x,y,z in [0,1]**3
|
253
|
+
puts [x, y, z].join(',')
|
254
|
+
end
|
255
|
+
</pre>
|
256
|
+
<p>
|
257
|
+
produces the following output
|
258
|
+
</p>
|
259
|
+
<pre>
|
260
|
+
0,0,0
|
261
|
+
0,0,1
|
262
|
+
0,1,0
|
263
|
+
0,1,1
|
264
|
+
1,0,0
|
265
|
+
1,0,1
|
266
|
+
1,1,0
|
267
|
+
1,1,1
|
268
|
+
</pre>
|
269
|
+
<p>
|
270
|
+
It also works with <a href="Range.html">Range</a> objects.
|
271
|
+
</p>
|
272
|
+
</div>
|
273
|
+
</div>
|
274
|
+
|
275
|
+
<div id="method-M000024" class="method-detail">
|
276
|
+
<a name="M000024"></a>
|
277
|
+
|
278
|
+
<div class="method-heading">
|
279
|
+
<span class="method-name">cartesian</span><span class="method-args">(other)</span>
|
280
|
+
</div>
|
281
|
+
|
282
|
+
<div class="method-description">
|
283
|
+
<p>
|
284
|
+
Alias for <a href="Cartesian.html#M000023">x</a>
|
285
|
+
</p>
|
286
|
+
</div>
|
287
|
+
</div>
|
288
|
+
|
289
|
+
<div id="method-M000022" class="method-detail">
|
290
|
+
<a name="M000022"></a>
|
291
|
+
|
292
|
+
<div class="method-heading">
|
293
|
+
<a href="Cartesian.src/M000022.html" target="Code" class="method-signature"
|
294
|
+
onclick="popupCode('Cartesian.src/M000022.html');return false;">
|
295
|
+
<span class="method-name">joined_cartesian</span><span class="method-args">(other)</span>
|
296
|
+
</a>
|
297
|
+
</div>
|
298
|
+
|
299
|
+
<div class="method-description">
|
300
|
+
<p>
|
301
|
+
<a href="Cartesian.html#M000021">Cartesian.joined_product</a> for mixin.
|
302
|
+
</p>
|
303
|
+
</div>
|
304
|
+
</div>
|
305
|
+
|
306
|
+
<div id="method-M000026" class="method-detail">
|
307
|
+
<a name="M000026"></a>
|
308
|
+
|
309
|
+
<div class="method-heading">
|
310
|
+
<a href="Cartesian.src/M000026.html" target="Code" class="method-signature"
|
311
|
+
onclick="popupCode('Cartesian.src/M000026.html');return false;">
|
312
|
+
<span class="method-name">left_product</span><span class="method-args">(other)</span>
|
313
|
+
</a>
|
314
|
+
</div>
|
315
|
+
|
316
|
+
<div class="method-description">
|
317
|
+
</div>
|
318
|
+
</div>
|
319
|
+
|
320
|
+
<div id="method-M000028" class="method-detail">
|
321
|
+
<a name="M000028"></a>
|
322
|
+
|
323
|
+
<div class="method-heading">
|
324
|
+
<span class="method-name">power!</span><span class="method-args">(fixnum)</span>
|
325
|
+
</div>
|
326
|
+
|
327
|
+
<div class="method-description">
|
328
|
+
<p>
|
329
|
+
Alias for #**
|
330
|
+
</p>
|
331
|
+
</div>
|
332
|
+
</div>
|
333
|
+
|
334
|
+
<div id="method-M000025" class="method-detail">
|
335
|
+
<a name="M000025"></a>
|
336
|
+
|
337
|
+
<div class="method-heading">
|
338
|
+
<span class="method-name">right_product</span><span class="method-args">(other)</span>
|
339
|
+
</div>
|
340
|
+
|
341
|
+
<div class="method-description">
|
342
|
+
<p>
|
343
|
+
Alias for <a href="Cartesian.html#M000023">x</a>
|
344
|
+
</p>
|
345
|
+
</div>
|
346
|
+
</div>
|
347
|
+
|
348
|
+
<div id="method-M000023" class="method-detail">
|
349
|
+
<a name="M000023"></a>
|
350
|
+
|
351
|
+
<div class="method-heading">
|
352
|
+
<a href="Cartesian.src/M000023.html" target="Code" class="method-signature"
|
353
|
+
onclick="popupCode('Cartesian.src/M000023.html');return false;">
|
354
|
+
<span class="method-name">x</span><span class="method-args">(other)</span>
|
355
|
+
</a>
|
356
|
+
</div>
|
357
|
+
|
358
|
+
<div class="method-description">
|
359
|
+
<p>
|
360
|
+
Convenient way of iterating over the elements. Preferable when the <a
|
361
|
+
href="Cartesian.html#M000024">cartesian</a> <a
|
362
|
+
href="Cartesian.html#M000020">product</a> array is not needed, for the
|
363
|
+
consumption of memory is fixed and very small, in contrast with the
|
364
|
+
exponential memory requirements of the conventional approach.
|
365
|
+
</p>
|
366
|
+
<pre>
|
367
|
+
for row, col in (1..10).x(1..30)
|
368
|
+
Matrix[row, col] = row**2 + col**3
|
369
|
+
end
|
370
|
+
</pre>
|
371
|
+
<p>
|
372
|
+
Of course, calls can be chained as in
|
373
|
+
</p>
|
374
|
+
<pre>
|
375
|
+
for x, y, z in (1..10).x(1..10).x(1..10)
|
376
|
+
# ... do something ...
|
377
|
+
end
|
378
|
+
</pre>
|
379
|
+
<p>
|
380
|
+
Beware that both <tt>self</tt> and <tt>other</tt> must implement
|
381
|
+
<tt>to_a</tt>, i.e., be convertible to array.
|
382
|
+
</p>
|
383
|
+
</div>
|
384
|
+
</div>
|
385
|
+
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
|
390
|
+
</div>
|
391
|
+
|
392
|
+
|
393
|
+
<div id="validator-badges">
|
394
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
395
|
+
</div>
|
396
|
+
|
397
|
+
</body>
|
398
|
+
</html>
|