rangops 1.0.0.beta1
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +19 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/docs/README_md.html +150 -0
- data/docs/Rangops/Set.html +719 -0
- data/docs/Rangops.html +105 -0
- data/docs/created.rid +3 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +683 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +159 -0
- data/docs/js/darkfish.js +120 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +190 -0
- data/lib/rangops/set.rb +183 -0
- data/lib/rangops/version.rb +3 -0
- data/lib/rangops.rb +9 -0
- data/rangops.gemspec +38 -0
- metadata +141 -0
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
|
|
8
|
+
<title>module Rangops::Set - Rangops</title>
|
|
9
|
+
|
|
10
|
+
<meta name="keywords" content="ruby,module,Rangops::Set">
|
|
11
|
+
|
|
12
|
+
<meta name="description" content="module Rangops::Set: Module defining basic set operations that can be performed on ranges. union * intersection * relative complement * symmetric difference along with so">
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
<script type="text/javascript">
|
|
16
|
+
var rdoc_rel_prefix = "../";
|
|
17
|
+
var index_rel_prefix = "../";
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<script src="../js/navigation.js" defer></script>
|
|
21
|
+
<script src="../js/search.js" defer></script>
|
|
22
|
+
<script src="../js/search_index.js" defer></script>
|
|
23
|
+
<script src="../js/searcher.js" defer></script>
|
|
24
|
+
<script src="../js/darkfish.js" defer></script>
|
|
25
|
+
|
|
26
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
|
27
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<body id="top" role="document" class="module">
|
|
31
|
+
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
|
|
32
|
+
<span aria-hidden="true">☰</span>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<nav id="navigation" role="navigation">
|
|
37
|
+
<div id="project-navigation">
|
|
38
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
|
39
|
+
<h2>
|
|
40
|
+
<a href="../index.html" rel="home">Home</a>
|
|
41
|
+
</h2>
|
|
42
|
+
|
|
43
|
+
<div id="table-of-contents-navigation">
|
|
44
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
|
45
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
|
46
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
|
51
|
+
<form action="#" method="get" accept-charset="utf-8">
|
|
52
|
+
<div id="search-field-wrapper">
|
|
53
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
|
54
|
+
aria-autocomplete="list" aria-controls="search-results"
|
|
55
|
+
type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
|
|
56
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<ul id="search-results" aria-label="Search Results"
|
|
60
|
+
aria-busy="false" aria-expanded="false"
|
|
61
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
|
62
|
+
</form>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
<div class="nav-section">
|
|
74
|
+
<h3>Class Methods</h3>
|
|
75
|
+
<ul class="link-list" role="directory">
|
|
76
|
+
<li ><a href="#method-c-sort_by_boundaries">sort_by_boundaries</a></li>
|
|
77
|
+
</ul>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
<div class="nav-section">
|
|
83
|
+
<h3>Instance Methods</h3>
|
|
84
|
+
<ul class="link-list" role="directory">
|
|
85
|
+
<li ><a href="#method-i-26">&</a></li>
|
|
86
|
+
<li ><a href="#method-i-2B">+</a></li>
|
|
87
|
+
<li ><a href="#method-i-2D">-</a></li>
|
|
88
|
+
<li ><a href="#method-i-7C">|</a></li>
|
|
89
|
+
<li ><a href="#method-i-complement">complement</a></li>
|
|
90
|
+
<li ><a href="#method-i-contains-3F">contains?</a></li>
|
|
91
|
+
<li ><a href="#method-i-difference">difference</a></li>
|
|
92
|
+
<li ><a href="#method-i-disjoint-3F">disjoint?</a></li>
|
|
93
|
+
<li ><a href="#method-i-intersect-3F">intersect?</a></li>
|
|
94
|
+
<li ><a href="#method-i-intersection">intersection</a></li>
|
|
95
|
+
<li ><a href="#method-i-is_contained_by-3F">is_contained_by?</a></li>
|
|
96
|
+
<li ><a href="#method-i-proper_subset-3F">proper_subset?</a></li>
|
|
97
|
+
<li ><a href="#method-i-proper_superset-3F">proper_superset?</a></li>
|
|
98
|
+
<li ><a href="#method-i-subset-3F">subset?</a></li>
|
|
99
|
+
<li ><a href="#method-i-superset-3F">superset?</a></li>
|
|
100
|
+
<li ><a href="#method-i-union">union</a></li>
|
|
101
|
+
</ul>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
<footer id="validator-badges" role="contentinfo">
|
|
107
|
+
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
|
108
|
+
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.14.2.
|
|
109
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
|
110
|
+
</footer>
|
|
111
|
+
|
|
112
|
+
</nav>
|
|
113
|
+
|
|
114
|
+
<main role="main" aria-labelledby="module-Rangops::Set">
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
<ol role="navigation" aria-label="breadcrumb" class="breadcrumb">
|
|
118
|
+
|
|
119
|
+
<li>
|
|
120
|
+
|
|
121
|
+
<a href="../Rangops.html">Rangops</a><span>::</span>
|
|
122
|
+
|
|
123
|
+
</li>
|
|
124
|
+
|
|
125
|
+
<li>
|
|
126
|
+
|
|
127
|
+
<span>Set</span>
|
|
128
|
+
|
|
129
|
+
</li>
|
|
130
|
+
|
|
131
|
+
</ol>
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
<h1 id="module-Rangops::Set" class="anchor-link module">
|
|
135
|
+
module Rangops::Set
|
|
136
|
+
</h1>
|
|
137
|
+
|
|
138
|
+
<section class="description">
|
|
139
|
+
|
|
140
|
+
<p>Module defining basic set operations that can be performed on ranges.</p>
|
|
141
|
+
<ul><li>
|
|
142
|
+
<p>union</p>
|
|
143
|
+
</li><li>
|
|
144
|
+
<p>intersection</p>
|
|
145
|
+
</li><li>
|
|
146
|
+
<p>relative complement</p>
|
|
147
|
+
</li><li>
|
|
148
|
+
<p>symmetric difference</p>
|
|
149
|
+
</li></ul>
|
|
150
|
+
|
|
151
|
+
<p>along with some convenient aliases and predicates. Loosely follows conventions of <a href="Set.html"><code>Set</code></a> module from standard library.</p>
|
|
152
|
+
|
|
153
|
+
<p>Operations involving 2 ranges require them to overlap to produce result. If the result of operation cannot be expressed as single range, an array of ranges is returned.</p>
|
|
154
|
+
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
<section id="5Buntitled-5D" class="documentation-section anchor-link">
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section anchor-link">
|
|
164
|
+
<header>
|
|
165
|
+
<h3>Public Class Methods</h3>
|
|
166
|
+
</header>
|
|
167
|
+
|
|
168
|
+
<div id="method-c-sort_by_boundaries" class="method-detail anchor-link ">
|
|
169
|
+
<div class="method-header">
|
|
170
|
+
<div class="method-heading">
|
|
171
|
+
<a href="#method-c-sort_by_boundaries" title="Link to this method">
|
|
172
|
+
<span class="method-name">sort_by_boundaries</span>
|
|
173
|
+
<span class="method-args">(a, b)</span>
|
|
174
|
+
</a>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<div class="method-controls">
|
|
179
|
+
<details class="method-source-toggle">
|
|
180
|
+
<summary>Source</summary>
|
|
181
|
+
</details>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<div class="method-description">
|
|
185
|
+
<div class="method-source-code" id="sort_by_boundaries-source">
|
|
186
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 175</span>
|
|
187
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">sort_by_boundaries</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
|
|
188
|
+
<span class="ruby-identifier">ary</span> = [<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>]
|
|
189
|
+
<span class="ruby-identifier">lower</span> = <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">begin</span>.<span class="ruby-identifier">nil?</span> } <span class="ruby-operator">||</span> <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">&</span><span class="ruby-value">:begin</span>).<span class="ruby-identifier">first</span>
|
|
190
|
+
<span class="ruby-identifier">upper</span> = <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">end</span>.<span class="ruby-identifier">nil?</span> } <span class="ruby-operator">||</span> <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">&</span><span class="ruby-value">:end</span>).<span class="ruby-identifier">last</span>
|
|
191
|
+
[<span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span>]
|
|
192
|
+
<span class="ruby-keyword">end</span></pre>
|
|
193
|
+
</div>
|
|
194
|
+
<p>Determine which range has lower begin, and which one higher end.</p>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
</section>
|
|
201
|
+
|
|
202
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section anchor-link">
|
|
203
|
+
<header>
|
|
204
|
+
<h3>Public Instance Methods</h3>
|
|
205
|
+
</header>
|
|
206
|
+
|
|
207
|
+
<div id="method-i-26" class="method-detail anchor-link method-alias">
|
|
208
|
+
<div class="method-header">
|
|
209
|
+
<div class="method-heading">
|
|
210
|
+
<a href="#method-i-26" title="Link to this method">
|
|
211
|
+
<span class="method-name">&</span>
|
|
212
|
+
<span class="method-args">(other)</span>
|
|
213
|
+
</a>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
<div class="method-description">
|
|
219
|
+
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
<div class="aliases">
|
|
224
|
+
Alias for: <a href="Set.html#method-i-intersection">intersection</a>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
<div id="method-i-2B" class="method-detail anchor-link method-alias">
|
|
229
|
+
<div class="method-header">
|
|
230
|
+
<div class="method-heading">
|
|
231
|
+
<a href="#method-i-2B" title="Link to this method">
|
|
232
|
+
<span class="method-name">+</span>
|
|
233
|
+
<span class="method-args">(other)</span>
|
|
234
|
+
</a>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
<div class="method-description">
|
|
240
|
+
|
|
241
|
+
</div>
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
<div class="aliases">
|
|
245
|
+
Alias for: <a href="Set.html#method-i-union">union</a>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
<div id="method-i-2D" class="method-detail anchor-link method-alias">
|
|
250
|
+
<div class="method-header">
|
|
251
|
+
<div class="method-heading">
|
|
252
|
+
<a href="#method-i-2D" title="Link to this method">
|
|
253
|
+
<span class="method-name">-</span>
|
|
254
|
+
<span class="method-args">(other)</span>
|
|
255
|
+
</a>
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
<div class="method-description">
|
|
261
|
+
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
<div class="aliases">
|
|
266
|
+
Alias for: <a href="Set.html#method-i-difference">difference</a>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<div id="method-i-7C" class="method-detail anchor-link method-alias">
|
|
271
|
+
<div class="method-header">
|
|
272
|
+
<div class="method-heading">
|
|
273
|
+
<a href="#method-i-7C" title="Link to this method">
|
|
274
|
+
<span class="method-name">|</span>
|
|
275
|
+
<span class="method-args">(other)</span>
|
|
276
|
+
</a>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
<div class="method-description">
|
|
282
|
+
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
<div class="aliases">
|
|
287
|
+
Alias for: <a href="Set.html#method-i-union">union</a>
|
|
288
|
+
</div>
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
<div id="method-i-complement" class="method-detail anchor-link ">
|
|
292
|
+
<div class="method-header">
|
|
293
|
+
<div class="method-heading">
|
|
294
|
+
<a href="#method-i-complement" title="Link to this method">
|
|
295
|
+
<span class="method-name">complement</span>
|
|
296
|
+
<span class="method-args">(other)</span>
|
|
297
|
+
</a>
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<div class="method-controls">
|
|
302
|
+
<details class="method-source-toggle">
|
|
303
|
+
<summary>Source</summary>
|
|
304
|
+
</details>
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
<div class="method-description">
|
|
308
|
+
<div class="method-source-code" id="complement-source">
|
|
309
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 61</span>
|
|
310
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">complement</span>(<span class="ruby-identifier">other</span>)
|
|
311
|
+
<span class="ruby-identifier">validate_args</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
312
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
313
|
+
|
|
314
|
+
<span class="ruby-identifier">_</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
315
|
+
<span class="ruby-identifier">new_begin</span> = [<span class="ruby-keyword">self</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">other</span>.<span class="ruby-identifier">end</span>].<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">min</span>
|
|
316
|
+
<span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">new_begin</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">exclude_end?</span>)
|
|
317
|
+
<span class="ruby-keyword">end</span></pre>
|
|
318
|
+
</div>
|
|
319
|
+
<p>Relative complement of 2 ranges. Returns a range covering elements from <code>other</code> that are not covered by <code>self</code>. Returns <code>nil</code> if ranges don’t overlap.</p>
|
|
320
|
+
|
|
321
|
+
<pre>(1..10).complement(5..15)
|
|
322
|
+
=> 10..15</pre>
|
|
323
|
+
</div>
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
</div>
|
|
327
|
+
|
|
328
|
+
<div id="method-i-contains-3F" class="method-detail anchor-link method-alias">
|
|
329
|
+
<div class="method-header">
|
|
330
|
+
<div class="method-heading">
|
|
331
|
+
<a href="#method-i-contains-3F" title="Link to this method">
|
|
332
|
+
<span class="method-name">contains?</span>
|
|
333
|
+
<span class="method-args">(other)</span>
|
|
334
|
+
</a>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
<div class="method-description">
|
|
340
|
+
|
|
341
|
+
</div>
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
<div class="aliases">
|
|
345
|
+
Alias for: <a href="Set.html#method-i-superset-3F">superset?</a>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
|
|
349
|
+
<div id="method-i-difference" class="method-detail anchor-link ">
|
|
350
|
+
<div class="method-header">
|
|
351
|
+
<div class="method-heading">
|
|
352
|
+
<a href="#method-i-difference" title="Link to this method">
|
|
353
|
+
<span class="method-name">difference</span>
|
|
354
|
+
<span class="method-args">(other)</span>
|
|
355
|
+
</a>
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
|
|
359
|
+
<div class="method-controls">
|
|
360
|
+
<details class="method-source-toggle">
|
|
361
|
+
<summary>Source</summary>
|
|
362
|
+
</details>
|
|
363
|
+
</div>
|
|
364
|
+
|
|
365
|
+
<div class="method-description">
|
|
366
|
+
<div class="method-source-code" id="difference-source">
|
|
367
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 79</span>
|
|
368
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">difference</span>(<span class="ruby-identifier">other</span>)
|
|
369
|
+
<span class="ruby-identifier">validate_args</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
370
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
371
|
+
|
|
372
|
+
<span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
373
|
+
[<span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">begin</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">begin</span>),
|
|
374
|
+
<span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">exclude_end?</span>)]
|
|
375
|
+
<span class="ruby-keyword">end</span></pre>
|
|
376
|
+
</div>
|
|
377
|
+
<p>Symmetric difference of 2 ranges. Returns ranges covering elements of both operands, excluding elements common for both of them. Returns <code>nil</code> if ranges don’t overlap.</p>
|
|
378
|
+
|
|
379
|
+
<pre>(1..10).difference(5..15)
|
|
380
|
+
=> [1..5, 10..15]
|
|
381
|
+
|
|
382
|
+
(11..19) - (15..28)
|
|
383
|
+
=> [11..15, 19..28]</pre>
|
|
384
|
+
</div>
|
|
385
|
+
|
|
386
|
+
<div class="aliases">
|
|
387
|
+
Also aliased as: <a href="Set.html#method-i-2D">-</a>
|
|
388
|
+
</div>
|
|
389
|
+
|
|
390
|
+
</div>
|
|
391
|
+
|
|
392
|
+
<div id="method-i-disjoint-3F" class="method-detail anchor-link ">
|
|
393
|
+
<div class="method-header">
|
|
394
|
+
<div class="method-heading">
|
|
395
|
+
<a href="#method-i-disjoint-3F" title="Link to this method">
|
|
396
|
+
<span class="method-name">disjoint?</span>
|
|
397
|
+
<span class="method-args">(other)</span>
|
|
398
|
+
</a>
|
|
399
|
+
</div>
|
|
400
|
+
</div>
|
|
401
|
+
|
|
402
|
+
<div class="method-controls">
|
|
403
|
+
<details class="method-source-toggle">
|
|
404
|
+
<summary>Source</summary>
|
|
405
|
+
</details>
|
|
406
|
+
</div>
|
|
407
|
+
|
|
408
|
+
<div class="method-description">
|
|
409
|
+
<div class="method-source-code" id="disjoint-3F-source">
|
|
410
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 104</span>
|
|
411
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">disjoint?</span>(<span class="ruby-identifier">other</span>)
|
|
412
|
+
<span class="ruby-operator">!</span><span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
413
|
+
<span class="ruby-keyword">end</span></pre>
|
|
414
|
+
</div>
|
|
415
|
+
<p>Opposite of ‘intersect?.</p>
|
|
416
|
+
</div>
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
<div id="method-i-intersect-3F" class="method-detail anchor-link ">
|
|
422
|
+
<div class="method-header">
|
|
423
|
+
<div class="method-heading">
|
|
424
|
+
<a href="#method-i-intersect-3F" title="Link to this method">
|
|
425
|
+
<span class="method-name">intersect?</span>
|
|
426
|
+
<span class="method-args">(other)</span>
|
|
427
|
+
</a>
|
|
428
|
+
</div>
|
|
429
|
+
</div>
|
|
430
|
+
|
|
431
|
+
<div class="method-controls">
|
|
432
|
+
<details class="method-source-toggle">
|
|
433
|
+
<summary>Source</summary>
|
|
434
|
+
</details>
|
|
435
|
+
</div>
|
|
436
|
+
|
|
437
|
+
<div class="method-description">
|
|
438
|
+
<div class="method-source-code" id="intersect-3F-source">
|
|
439
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 97</span>
|
|
440
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
441
|
+
<span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
442
|
+
<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">upper</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">end</span>)
|
|
443
|
+
<span class="ruby-keyword">end</span></pre>
|
|
444
|
+
</div>
|
|
445
|
+
<p>Checks if 2 ranges have any common elements.</p>
|
|
446
|
+
|
|
447
|
+
<pre> (1..10).intersect?(8..15)
|
|
448
|
+
=> true
|
|
449
|
+
|
|
450
|
+
(1..10).intersect?(11..15)
|
|
451
|
+
=> false</pre>
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
</div>
|
|
456
|
+
|
|
457
|
+
<div id="method-i-intersection" class="method-detail anchor-link ">
|
|
458
|
+
<div class="method-header">
|
|
459
|
+
<div class="method-heading">
|
|
460
|
+
<a href="#method-i-intersection" title="Link to this method">
|
|
461
|
+
<span class="method-name">intersection</span>
|
|
462
|
+
<span class="method-args">(other)</span>
|
|
463
|
+
</a>
|
|
464
|
+
</div>
|
|
465
|
+
</div>
|
|
466
|
+
|
|
467
|
+
<div class="method-controls">
|
|
468
|
+
<details class="method-source-toggle">
|
|
469
|
+
<summary>Source</summary>
|
|
470
|
+
</details>
|
|
471
|
+
</div>
|
|
472
|
+
|
|
473
|
+
<div class="method-description">
|
|
474
|
+
<div class="method-source-code" id="intersection-source">
|
|
475
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 46</span>
|
|
476
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">intersection</span>(<span class="ruby-identifier">other</span>)
|
|
477
|
+
<span class="ruby-identifier">validate_args</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
478
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
479
|
+
|
|
480
|
+
<span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
481
|
+
<span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">upper</span>.<span class="ruby-identifier">begin</span>, <span class="ruby-identifier">lower</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">lower</span>.<span class="ruby-identifier">exclude_end?</span>)
|
|
482
|
+
<span class="ruby-keyword">end</span></pre>
|
|
483
|
+
</div>
|
|
484
|
+
<p>Intersection of 2 ranges. Returns a range covering elements common to both ranges. Returns <code>nil</code> if ranges don’t overlap.</p>
|
|
485
|
+
|
|
486
|
+
<pre>(1..10).intersection(5..15)
|
|
487
|
+
=> 5..10
|
|
488
|
+
|
|
489
|
+
(5..10) & (9..24)
|
|
490
|
+
=> 9..10</pre>
|
|
491
|
+
</div>
|
|
492
|
+
|
|
493
|
+
<div class="aliases">
|
|
494
|
+
Also aliased as: <a href="Set.html#method-i-26">&</a>
|
|
495
|
+
</div>
|
|
496
|
+
|
|
497
|
+
</div>
|
|
498
|
+
|
|
499
|
+
<div id="method-i-is_contained_by-3F" class="method-detail anchor-link method-alias">
|
|
500
|
+
<div class="method-header">
|
|
501
|
+
<div class="method-heading">
|
|
502
|
+
<a href="#method-i-is_contained_by-3F" title="Link to this method">
|
|
503
|
+
<span class="method-name">is_contained_by?</span>
|
|
504
|
+
<span class="method-args">(other)</span>
|
|
505
|
+
</a>
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
<div class="method-description">
|
|
511
|
+
|
|
512
|
+
</div>
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
<div class="aliases">
|
|
516
|
+
Alias for: <a href="Set.html#method-i-subset-3F">subset?</a>
|
|
517
|
+
</div>
|
|
518
|
+
</div>
|
|
519
|
+
|
|
520
|
+
<div id="method-i-proper_subset-3F" class="method-detail anchor-link ">
|
|
521
|
+
<div class="method-header">
|
|
522
|
+
<div class="method-heading">
|
|
523
|
+
<a href="#method-i-proper_subset-3F" title="Link to this method">
|
|
524
|
+
<span class="method-name">proper_subset?</span>
|
|
525
|
+
<span class="method-args">(other)</span>
|
|
526
|
+
</a>
|
|
527
|
+
</div>
|
|
528
|
+
</div>
|
|
529
|
+
|
|
530
|
+
<div class="method-controls">
|
|
531
|
+
<details class="method-source-toggle">
|
|
532
|
+
<summary>Source</summary>
|
|
533
|
+
</details>
|
|
534
|
+
</div>
|
|
535
|
+
|
|
536
|
+
<div class="method-description">
|
|
537
|
+
<div class="method-source-code" id="proper_subset-3F-source">
|
|
538
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 162</span>
|
|
539
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proper_subset?</span>(<span class="ruby-identifier">other</span>)
|
|
540
|
+
<span class="ruby-identifier">subset?</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">&&</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>
|
|
541
|
+
<span class="ruby-keyword">end</span></pre>
|
|
542
|
+
</div>
|
|
543
|
+
<p>Checks if <code>self</code> is proper subset of <code>other</code>, i.e. is subset and has elements not present in <code>other</code>.</p>
|
|
544
|
+
|
|
545
|
+
<pre>(1..10).proper_subset?(0..12)
|
|
546
|
+
=> true
|
|
547
|
+
|
|
548
|
+
(1..10).proper_subset?(1..10)
|
|
549
|
+
=> false</pre>
|
|
550
|
+
</div>
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
</div>
|
|
554
|
+
|
|
555
|
+
<div id="method-i-proper_superset-3F" class="method-detail anchor-link ">
|
|
556
|
+
<div class="method-header">
|
|
557
|
+
<div class="method-heading">
|
|
558
|
+
<a href="#method-i-proper_superset-3F" title="Link to this method">
|
|
559
|
+
<span class="method-name">proper_superset?</span>
|
|
560
|
+
<span class="method-args">(other)</span>
|
|
561
|
+
</a>
|
|
562
|
+
</div>
|
|
563
|
+
</div>
|
|
564
|
+
|
|
565
|
+
<div class="method-controls">
|
|
566
|
+
<details class="method-source-toggle">
|
|
567
|
+
<summary>Source</summary>
|
|
568
|
+
</details>
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
<div class="method-description">
|
|
572
|
+
<div class="method-source-code" id="proper_superset-3F-source">
|
|
573
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 133</span>
|
|
574
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proper_superset?</span>(<span class="ruby-identifier">other</span>)
|
|
575
|
+
<span class="ruby-identifier">superset?</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">&&</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>
|
|
576
|
+
<span class="ruby-keyword">end</span></pre>
|
|
577
|
+
</div>
|
|
578
|
+
<p>Checks if <code>self</code> is proper superset of <code>other</code>, i.e. is superset and has elements not present in <code>other</code>.</p>
|
|
579
|
+
|
|
580
|
+
<pre>(1..10).proper_superset?(2..5)
|
|
581
|
+
=> true
|
|
582
|
+
|
|
583
|
+
(1..10).proper_superset?(1..10)
|
|
584
|
+
=> false</pre>
|
|
585
|
+
</div>
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
</div>
|
|
589
|
+
|
|
590
|
+
<div id="method-i-subset-3F" class="method-detail anchor-link ">
|
|
591
|
+
<div class="method-header">
|
|
592
|
+
<div class="method-heading">
|
|
593
|
+
<a href="#method-i-subset-3F" title="Link to this method">
|
|
594
|
+
<span class="method-name">subset?</span>
|
|
595
|
+
<span class="method-args">(other)</span>
|
|
596
|
+
</a>
|
|
597
|
+
</div>
|
|
598
|
+
</div>
|
|
599
|
+
|
|
600
|
+
<div class="method-controls">
|
|
601
|
+
<details class="method-source-toggle">
|
|
602
|
+
<summary>Source</summary>
|
|
603
|
+
</details>
|
|
604
|
+
</div>
|
|
605
|
+
|
|
606
|
+
<div class="method-description">
|
|
607
|
+
<div class="method-source-code" id="subset-3F-source">
|
|
608
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 148</span>
|
|
609
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">subset?</span>(<span class="ruby-identifier">other</span>)
|
|
610
|
+
<span class="ruby-identifier">other</span>.<span class="ruby-identifier">superset?</span>(<span class="ruby-keyword">self</span>)
|
|
611
|
+
<span class="ruby-keyword">end</span></pre>
|
|
612
|
+
</div>
|
|
613
|
+
<p>Checks if <code>self</code> is subset of <code>other</code>, i.e. all elements of <code>self</code> fit within <code>other</code>.</p>
|
|
614
|
+
|
|
615
|
+
<pre>(1..10).subset?(0..12)
|
|
616
|
+
=> true
|
|
617
|
+
|
|
618
|
+
(1..10).subset?(1..10)
|
|
619
|
+
=> true
|
|
620
|
+
|
|
621
|
+
(1..10).subset?(5..12)
|
|
622
|
+
=> false</pre>
|
|
623
|
+
</div>
|
|
624
|
+
|
|
625
|
+
<div class="aliases">
|
|
626
|
+
Also aliased as: <a href="Set.html#method-i-is_contained_by-3F">is_contained_by?</a>
|
|
627
|
+
</div>
|
|
628
|
+
|
|
629
|
+
</div>
|
|
630
|
+
|
|
631
|
+
<div id="method-i-superset-3F" class="method-detail anchor-link ">
|
|
632
|
+
<div class="method-header">
|
|
633
|
+
<div class="method-heading">
|
|
634
|
+
<a href="#method-i-superset-3F" title="Link to this method">
|
|
635
|
+
<span class="method-name">superset?</span>
|
|
636
|
+
<span class="method-args">(other)</span>
|
|
637
|
+
</a>
|
|
638
|
+
</div>
|
|
639
|
+
</div>
|
|
640
|
+
|
|
641
|
+
<div class="method-controls">
|
|
642
|
+
<details class="method-source-toggle">
|
|
643
|
+
<summary>Source</summary>
|
|
644
|
+
</details>
|
|
645
|
+
</div>
|
|
646
|
+
|
|
647
|
+
<div class="method-description">
|
|
648
|
+
<div class="method-source-code" id="superset-3F-source">
|
|
649
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 119</span>
|
|
650
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">superset?</span>(<span class="ruby-identifier">other</span>)
|
|
651
|
+
<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">end</span>)
|
|
652
|
+
<span class="ruby-keyword">end</span></pre>
|
|
653
|
+
</div>
|
|
654
|
+
<p>Checks if <code>self</code> is superset of <code>other</code>, i.e. all elements of <code>other</code> fit within <code>self</code>.</p>
|
|
655
|
+
|
|
656
|
+
<pre>(1..10).superset?(2..5)
|
|
657
|
+
=> true
|
|
658
|
+
|
|
659
|
+
(1..10).superset?(1..10)
|
|
660
|
+
=> true
|
|
661
|
+
|
|
662
|
+
(1..10).superset?(5..12)
|
|
663
|
+
=> false</pre>
|
|
664
|
+
</div>
|
|
665
|
+
|
|
666
|
+
<div class="aliases">
|
|
667
|
+
Also aliased as: <a href="Set.html#method-i-contains-3F">contains?</a>
|
|
668
|
+
</div>
|
|
669
|
+
|
|
670
|
+
</div>
|
|
671
|
+
|
|
672
|
+
<div id="method-i-union" class="method-detail anchor-link ">
|
|
673
|
+
<div class="method-header">
|
|
674
|
+
<div class="method-heading">
|
|
675
|
+
<a href="#method-i-union" title="Link to this method">
|
|
676
|
+
<span class="method-name">union</span>
|
|
677
|
+
<span class="method-args">(other)</span>
|
|
678
|
+
</a>
|
|
679
|
+
</div>
|
|
680
|
+
</div>
|
|
681
|
+
|
|
682
|
+
<div class="method-controls">
|
|
683
|
+
<details class="method-source-toggle">
|
|
684
|
+
<summary>Source</summary>
|
|
685
|
+
</details>
|
|
686
|
+
</div>
|
|
687
|
+
|
|
688
|
+
<div class="method-description">
|
|
689
|
+
<div class="method-source-code" id="union-source">
|
|
690
|
+
<pre><span class="ruby-comment"># File lib/rangops/set.rb, line 28</span>
|
|
691
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">union</span>(<span class="ruby-identifier">other</span>)
|
|
692
|
+
<span class="ruby-identifier">validate_args</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
693
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
|
|
694
|
+
|
|
695
|
+
<span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
|
|
696
|
+
<span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">begin</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">end</span>, <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">exclude_end?</span>)
|
|
697
|
+
<span class="ruby-keyword">end</span></pre>
|
|
698
|
+
</div>
|
|
699
|
+
<p>Union of 2 ranges. Returns a range covering sum of all elements belonging to both ranges. Returns <code>nil</code> if ranges don’t overlap.</p>
|
|
700
|
+
|
|
701
|
+
<pre>(1..10).union(5..15)
|
|
702
|
+
=> 1..15
|
|
703
|
+
(5..10) | (9..24)
|
|
704
|
+
=> 5..24
|
|
705
|
+
(1...10) + (10..30)
|
|
706
|
+
=> nil</pre>
|
|
707
|
+
</div>
|
|
708
|
+
|
|
709
|
+
<div class="aliases">
|
|
710
|
+
Also aliased as: <a href="Set.html#method-i-7C">|</a>, <a href="Set.html#method-i-2B">+</a>
|
|
711
|
+
</div>
|
|
712
|
+
|
|
713
|
+
</div>
|
|
714
|
+
|
|
715
|
+
</section>
|
|
716
|
+
|
|
717
|
+
</section>
|
|
718
|
+
</main>
|
|
719
|
+
|