shenanigans 1.0.14 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/shenanigans/hash/has_shape_pred.rb +1 -1
- data/lib/shenanigans/integer/divisible_by.rb +13 -0
- data/lib/shenanigans/integer.rb +1 -0
- data/lib/shenanigans.rb +1 -1
- data/test/integer/divisible_by_test.rb +16 -0
- metadata +8 -27
- data/doc/Array.html +0 -549
- data/doc/Hash.html +0 -438
- data/doc/Integer.html +0 -219
- data/doc/Kernel.html +0 -500
- data/doc/Module.html +0 -233
- data/doc/Object.html +0 -215
- data/doc/String.html +0 -300
- data/doc/_index.html +0 -185
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -496
- data/doc/file.README.html +0 -131
- data/doc/file_list.html +0 -56
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -131
- data/doc/js/app.js +0 -314
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -179
- data/doc/top-level-namespace.html +0 -112
data/doc/Array.html
DELETED
@@ -1,549 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Class: Array
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.24
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
-
|
17
|
-
<script type="text/javascript">
|
18
|
-
pathId = "Array";
|
19
|
-
relpath = '';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="_index.html">Index (A)</a> »
|
40
|
-
|
41
|
-
|
42
|
-
<span class="title">Array</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Class: Array
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
<dl>
|
70
|
-
<dt>Inherits:</dt>
|
71
|
-
<dd>
|
72
|
-
<span class="inheritName"><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></span>
|
73
|
-
|
74
|
-
<ul class="fullTree">
|
75
|
-
<li><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></li>
|
76
|
-
|
77
|
-
<li class="next">Array</li>
|
78
|
-
|
79
|
-
</ul>
|
80
|
-
<a href="#" class="inheritanceTree">show all</a>
|
81
|
-
|
82
|
-
</dd>
|
83
|
-
</dl>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
<dl>
|
96
|
-
<dt>Defined in:</dt>
|
97
|
-
<dd>lib/shenanigans/array/caret.rb<span class="defines">,<br />
|
98
|
-
lib/shenanigans/array/zip_with.rb,<br /> lib/shenanigans/array/reductions.rb,<br /> lib/shenanigans/array/random_subarray.rb</span>
|
99
|
-
</dd>
|
100
|
-
</dl>
|
101
|
-
|
102
|
-
</div>
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
<h2>
|
113
|
-
Instance Method Summary
|
114
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
115
|
-
</h2>
|
116
|
-
|
117
|
-
<ul class="summary">
|
118
|
-
|
119
|
-
<li class="public ">
|
120
|
-
<span class="summary_signature">
|
121
|
-
|
122
|
-
<a href="#%5E-instance_method" title="#^ (instance method)">#<strong>^</strong>(other) ⇒ Object </a>
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
</span>
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
<span class="summary_desc"><div class='inline'>
|
137
|
-
<p>Returns an array containing elements exclusive between two arrays.</p>
|
138
|
-
</div></span>
|
139
|
-
|
140
|
-
</li>
|
141
|
-
|
142
|
-
|
143
|
-
<li class="public ">
|
144
|
-
<span class="summary_signature">
|
145
|
-
|
146
|
-
<a href="#random_subarray-instance_method" title="#random_subarray (instance method)">#<strong>random_subarray</strong>(n = 1) ⇒ Object </a>
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
</span>
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
<span class="summary_desc"><div class='inline'>
|
161
|
-
<p>Generates random subarrays.</p>
|
162
|
-
</div></span>
|
163
|
-
|
164
|
-
</li>
|
165
|
-
|
166
|
-
|
167
|
-
<li class="public ">
|
168
|
-
<span class="summary_signature">
|
169
|
-
|
170
|
-
<a href="#reductions-instance_method" title="#reductions (instance method)">#<strong>reductions</strong>(*args, &block) ⇒ Object </a>
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
</span>
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
<span class="summary_desc"><div class='inline'>
|
185
|
-
<p>Similar to <code>reduce</code>/<code>inject</code>, but also returns intermediate values.</p>
|
186
|
-
</div></span>
|
187
|
-
|
188
|
-
</li>
|
189
|
-
|
190
|
-
|
191
|
-
<li class="public ">
|
192
|
-
<span class="summary_signature">
|
193
|
-
|
194
|
-
<a href="#zip_with-instance_method" title="#zip_with (instance method)">#<strong>zip_with</strong>(other, op = nil) ⇒ Object </a>
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
</span>
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
<span class="summary_desc"><div class='inline'>
|
209
|
-
<p>Zip <code>self</code> with <code>other</code>, combining the elements with the provided block or symbol.</p>
|
210
|
-
</div></span>
|
211
|
-
|
212
|
-
</li>
|
213
|
-
|
214
|
-
|
215
|
-
</ul>
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
<div id="instance_method_details" class="method_details_list">
|
221
|
-
<h2>Instance Method Details</h2>
|
222
|
-
|
223
|
-
|
224
|
-
<div class="method_details first">
|
225
|
-
<h3 class="signature first" id="^-instance_method">
|
226
|
-
|
227
|
-
#<strong>^</strong>(other) ⇒ <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
</h3><div class="docstring">
|
234
|
-
<div class="discussion">
|
235
|
-
|
236
|
-
<p>Returns an array containing elements exclusive between two arrays.</p>
|
237
|
-
|
238
|
-
|
239
|
-
</div>
|
240
|
-
</div>
|
241
|
-
<div class="tags">
|
242
|
-
|
243
|
-
<div class="examples">
|
244
|
-
<p class="tag_title">Examples:</p>
|
245
|
-
|
246
|
-
|
247
|
-
<pre class="example code"><code><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>3</span><span class='rbracket'>]</span> <span class='op'>^</span> <span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='int'>2</span><span class='comma'>,</span> <span class='int'>4</span><span class='rbracket'>]</span> <span class='comment'>#=> [3, 4]</span></code></pre>
|
248
|
-
|
249
|
-
</div>
|
250
|
-
|
251
|
-
|
252
|
-
</div><table class="source_code">
|
253
|
-
<tr>
|
254
|
-
<td>
|
255
|
-
<pre class="lines">
|
256
|
-
|
257
|
-
|
258
|
-
6
|
259
|
-
7
|
260
|
-
8</pre>
|
261
|
-
</td>
|
262
|
-
<td>
|
263
|
-
<pre class="code"><span class="info file"># File 'lib/shenanigans/array/caret.rb', line 6</span>
|
264
|
-
|
265
|
-
<span class='kw'>def</span> <span class='op'>^</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
|
266
|
-
<span class='lparen'>(</span><span class='kw'>self</span> <span class='op'>-</span> <span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span> <span class='op'>|</span> <span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span> <span class='op'>-</span> <span class='kw'>self</span><span class='rparen'>)</span>
|
267
|
-
<span class='kw'>end</span></pre>
|
268
|
-
</td>
|
269
|
-
</tr>
|
270
|
-
</table>
|
271
|
-
</div>
|
272
|
-
|
273
|
-
<div class="method_details ">
|
274
|
-
<h3 class="signature " id="random_subarray-instance_method">
|
275
|
-
|
276
|
-
#<strong>random_subarray</strong>(n = 1) ⇒ <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
</h3><div class="docstring">
|
283
|
-
<div class="discussion">
|
284
|
-
|
285
|
-
<p>Generates random subarrays. Uses random numbers and bit-fiddling to assure performant uniform distributions even for large arrays.</p>
|
286
|
-
|
287
|
-
|
288
|
-
</div>
|
289
|
-
</div>
|
290
|
-
<div class="tags">
|
291
|
-
|
292
|
-
<div class="examples">
|
293
|
-
<p class="tag_title">Examples:</p>
|
294
|
-
|
295
|
-
|
296
|
-
<pre class="example code"><code><span class='id identifier rubyid_a'>a</span> <span class='op'>=</span> <span class='op'>*</span><span class='int'>1</span><span class='op'>..</span><span class='int'>5</span>
|
297
|
-
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_random_subarray'>random_subarray</span><span class='lparen'>(</span><span class='int'>3</span><span class='rparen'>)</span> <span class='comment'>#=> [[1, 3, 5], [2, 4], [1, 3, 4, 5]]</span></code></pre>
|
298
|
-
|
299
|
-
</div>
|
300
|
-
|
301
|
-
<p class="tag_title">Raises:</p>
|
302
|
-
<ul class="raise">
|
303
|
-
|
304
|
-
<li>
|
305
|
-
|
306
|
-
|
307
|
-
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
</li>
|
312
|
-
|
313
|
-
</ul>
|
314
|
-
|
315
|
-
</div><table class="source_code">
|
316
|
-
<tr>
|
317
|
-
<td>
|
318
|
-
<pre class="lines">
|
319
|
-
|
320
|
-
|
321
|
-
10
|
322
|
-
11
|
323
|
-
12
|
324
|
-
13
|
325
|
-
14
|
326
|
-
15
|
327
|
-
16
|
328
|
-
17</pre>
|
329
|
-
</td>
|
330
|
-
<td>
|
331
|
-
<pre class="code"><span class="info file"># File 'lib/shenanigans/array/random_subarray.rb', line 10</span>
|
332
|
-
|
333
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_random_subarray'>random_subarray</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span> <span class='op'>=</span> <span class='int'>1</span><span class='rparen'>)</span>
|
334
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>negative argument</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='id identifier rubyid_n'>n</span> <span class='op'><</span> <span class='int'>0</span>
|
335
|
-
|
336
|
-
<span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span>
|
337
|
-
<span class='id identifier rubyid_r'>r</span> <span class='op'>=</span> <span class='id identifier rubyid_rand'>rand</span><span class='lparen'>(</span><span class='int'>2</span><span class='op'>**</span><span class='id identifier rubyid_size'>size</span><span class='rparen'>)</span>
|
338
|
-
<span class='id identifier rubyid_select'>select</span><span class='period'>.</span><span class='id identifier rubyid_with_index'>with_index</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid__'>_</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='op'>|</span> <span class='id identifier rubyid_r'>r</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='int'>1</span> <span class='rbrace'>}</span>
|
339
|
-
<span class='kw'>end</span>
|
340
|
-
<span class='kw'>end</span></pre>
|
341
|
-
</td>
|
342
|
-
</tr>
|
343
|
-
</table>
|
344
|
-
</div>
|
345
|
-
|
346
|
-
<div class="method_details ">
|
347
|
-
<h3 class="signature " id="reductions-instance_method">
|
348
|
-
|
349
|
-
#<strong>reductions</strong>(*args, &block) ⇒ <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
</h3><div class="docstring">
|
356
|
-
<div class="discussion">
|
357
|
-
|
358
|
-
<p>Similar to <code>reduce</code>/<code>inject</code>, but also returns intermediate values. Has the same interface as <code>reduce</code>/<code>inject</code>, so an initial value, an operator or both can be supplied. This method may eventually be moved to the <code>Enumerable</code> module.</p>
|
359
|
-
|
360
|
-
|
361
|
-
</div>
|
362
|
-
</div>
|
363
|
-
<div class="tags">
|
364
|
-
|
365
|
-
<div class="examples">
|
366
|
-
<p class="tag_title">Examples:</p>
|
367
|
-
|
368
|
-
|
369
|
-
<p class="example_title"><div class='inline'>
|
370
|
-
<p>Symbol argument</p>
|
371
|
-
</div></p>
|
372
|
-
|
373
|
-
<pre class="example code"><code><span class='id identifier rubyid_a'>a</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='int'>4</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_a'>to_a</span>
|
374
|
-
<span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_reductions'>reductions</span><span class='lparen'>(</span><span class='symbol'>:+</span><span class='rparen'>)</span> <span class='comment'>#=> 10</span></code></pre>
|
375
|
-
|
376
|
-
|
377
|
-
<p class="example_title"><div class='inline'>
|
378
|
-
<p>Initial value and symbol argument</p>
|
379
|
-
</div></p>
|
380
|
-
|
381
|
-
<pre class="example code"><code><span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_reductions'>reductions</span><span class='lparen'>(</span><span class='int'>50</span><span class='comma'>,</span> <span class='symbol'>:+</span><span class='rparen'>)</span> <span class='comment'>#=> 60</span></code></pre>
|
382
|
-
|
383
|
-
|
384
|
-
<p class="example_title"><div class='inline'>
|
385
|
-
<p>Block argument</p>
|
386
|
-
</div></p>
|
387
|
-
|
388
|
-
<pre class="example code"><code><span class='qwords_beg'>%w(</span><span class='tstring_content'>a</span><span class='words_sep'> </span><span class='tstring_content'>b</span><span class='words_sep'> </span><span class='tstring_content'>c</span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_reductions'>reductions</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_s1'>s1</span><span class='comma'>,</span> <span class='id identifier rubyid_s2'>s2</span><span class='op'>|</span> <span class='id identifier rubyid_s1'>s1</span><span class='op'>+</span><span class='id identifier rubyid_s2'>s2</span> <span class='rbrace'>}</span> <span class='comment'>#=> ["a", "ab", "abc"]</span></code></pre>
|
389
|
-
|
390
|
-
</div>
|
391
|
-
|
392
|
-
<p class="tag_title">Raises:</p>
|
393
|
-
<ul class="raise">
|
394
|
-
|
395
|
-
<li>
|
396
|
-
|
397
|
-
|
398
|
-
<span class='type'>(<tt>ArgumentError</tt>)</span>
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
</li>
|
403
|
-
|
404
|
-
</ul>
|
405
|
-
|
406
|
-
</div><table class="source_code">
|
407
|
-
<tr>
|
408
|
-
<td>
|
409
|
-
<pre class="lines">
|
410
|
-
|
411
|
-
|
412
|
-
14
|
413
|
-
15
|
414
|
-
16
|
415
|
-
17
|
416
|
-
18
|
417
|
-
19
|
418
|
-
20
|
419
|
-
21
|
420
|
-
22
|
421
|
-
23
|
422
|
-
24
|
423
|
-
25
|
424
|
-
26
|
425
|
-
27
|
426
|
-
28
|
427
|
-
29
|
428
|
-
30
|
429
|
-
31</pre>
|
430
|
-
</td>
|
431
|
-
<td>
|
432
|
-
<pre class="code"><span class="info file"># File 'lib/shenanigans/array/reductions.rb', line 14</span>
|
433
|
-
|
434
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_reductions'>reductions</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
435
|
-
<span class='id identifier rubyid_arr'>arr</span> <span class='op'>=</span> <span class='id identifier rubyid_dup'>dup</span>
|
436
|
-
|
437
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>1</span>
|
438
|
-
<span class='const'>Symbol</span> <span class='op'>===</span> <span class='lparen'>(</span><span class='id identifier rubyid_arg'>arg</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_op'>op</span> <span class='op'>=</span> <span class='id identifier rubyid_arg'>arg</span> <span class='op'>:</span> <span class='id identifier rubyid_initial'>initial</span> <span class='op'>=</span> <span class='id identifier rubyid_arg'>arg</span>
|
439
|
-
<span class='kw'>else</span>
|
440
|
-
<span class='id identifier rubyid_initial'>initial</span><span class='comma'>,</span> <span class='id identifier rubyid_op'>op</span><span class='comma'>,</span> <span class='id identifier rubyid__'>_</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span>
|
441
|
-
<span class='kw'>end</span>
|
442
|
-
|
443
|
-
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>ArgumentError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Need an operator or block</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_op'>op</span> <span class='op'>||</span> <span class='id identifier rubyid_block'>block</span>
|
444
|
-
|
445
|
-
<span class='id identifier rubyid_initial'>initial</span> <span class='op'>||=</span> <span class='id identifier rubyid_arr'>arr</span><span class='period'>.</span><span class='id identifier rubyid_shift'>shift</span>
|
446
|
-
|
447
|
-
<span class='id identifier rubyid_arr'>arr</span><span class='period'>.</span><span class='id identifier rubyid_inject'>inject</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='id identifier rubyid_initial'>initial</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='id identifier rubyid_initial'>initial</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='lparen'>(</span><span class='id identifier rubyid_acc'>acc</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_el'>el</span><span class='op'>|</span>
|
448
|
-
<span class='id identifier rubyid_val'>val</span> <span class='op'>=</span> <span class='id identifier rubyid_op'>op</span> <span class='op'>?</span> <span class='id identifier rubyid_acc'>acc</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_op'>op</span><span class='comma'>,</span> <span class='id identifier rubyid_el'>el</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='kw'>yield</span><span class='lparen'>(</span><span class='id identifier rubyid_acc'>acc</span><span class='comma'>,</span> <span class='id identifier rubyid_el'>el</span><span class='rparen'>)</span>
|
449
|
-
<span class='lbracket'>[</span><span class='id identifier rubyid_val'>val</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span> <span class='op'><<</span> <span class='id identifier rubyid_val'>val</span><span class='rbracket'>]</span>
|
450
|
-
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span>
|
451
|
-
<span class='kw'>end</span></pre>
|
452
|
-
</td>
|
453
|
-
</tr>
|
454
|
-
</table>
|
455
|
-
</div>
|
456
|
-
|
457
|
-
<div class="method_details ">
|
458
|
-
<h3 class="signature " id="zip_with-instance_method">
|
459
|
-
|
460
|
-
#<strong>zip_with</strong>(other, op = nil) ⇒ <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
</h3><div class="docstring">
|
467
|
-
<div class="discussion">
|
468
|
-
|
469
|
-
<p>Zip <code>self</code> with <code>other</code>, combining the elements with the provided block or symbol. The resulting array will be as long as the shorter of the two arrays.</p>
|
470
|
-
|
471
|
-
|
472
|
-
</div>
|
473
|
-
</div>
|
474
|
-
<div class="tags">
|
475
|
-
|
476
|
-
<div class="examples">
|
477
|
-
<p class="tag_title">Examples:</p>
|
478
|
-
|
479
|
-
|
480
|
-
<p class="example_title"><div class='inline'>
|
481
|
-
<p>With a symbol</p>
|
482
|
-
</div></p>
|
483
|
-
|
484
|
-
<pre class="example code"><code><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>2</span><span class='comma'>,</span><span class='int'>3</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_zip_with'>zip_with</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>6</span><span class='comma'>,</span><span class='int'>5</span><span class='comma'>,</span><span class='int'>4</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='symbol'>:+</span><span class='rparen'>)</span> <span class='comment'>#=> [7, 7, 7]
|
485
|
-
</span><span class='qwords_beg'>%w(</span><span class='tstring_content'>a</span><span class='words_sep'> </span><span class='tstring_content'>b</span><span class='tstring_end'>)</span></span><span class='period'>.</span><span class='id identifier rubyid_zip_with'>zip_with</span><span class='lparen'>(</span><span class='qwords_beg'>%w(</span><span class='tstring_content'>c</span><span class='words_sep'> </span><span class='tstring_content'>d</span><span class='tstring_end'>)</span></span><span class='comma'>,</span> <span class='symbol'>:+</span><span class='rparen'>)</span> <span class='comment'>#=> ["ac", "bd"]</span></code></pre>
|
486
|
-
|
487
|
-
|
488
|
-
<p class="example_title"><div class='inline'>
|
489
|
-
<p>With a block</p>
|
490
|
-
</div></p>
|
491
|
-
|
492
|
-
<pre class="example code"><code><span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>2</span><span class='comma'>,</span><span class='int'>3</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_zip_with'>zip_with</span><span class='lparen'>(</span><span class='lbracket'>[</span><span class='int'>6</span><span class='comma'>,</span><span class='int'>5</span><span class='comma'>,</span><span class='int'>4</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span><span class='id identifier rubyid_b'>b</span><span class='op'>|</span> <span class='int'>3</span> <span class='op'>*</span> <span class='id identifier rubyid_a'>a</span> <span class='op'>+</span> <span class='int'>2</span> <span class='op'>*</span> <span class='id identifier rubyid_b'>b</span> <span class='rbrace'>}</span><span class='comment'>#=> [15, 16, 17]</span>
|
493
|
-
</code></pre>
|
494
|
-
|
495
|
-
</div>
|
496
|
-
|
497
|
-
|
498
|
-
</div><table class="source_code">
|
499
|
-
<tr>
|
500
|
-
<td>
|
501
|
-
<pre class="lines">
|
502
|
-
|
503
|
-
|
504
|
-
12
|
505
|
-
13
|
506
|
-
14
|
507
|
-
15
|
508
|
-
16
|
509
|
-
17
|
510
|
-
18
|
511
|
-
19
|
512
|
-
20
|
513
|
-
21
|
514
|
-
22
|
515
|
-
23</pre>
|
516
|
-
</td>
|
517
|
-
<td>
|
518
|
-
<pre class="code"><span class="info file"># File 'lib/shenanigans/array/zip_with.rb', line 12</span>
|
519
|
-
|
520
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_zip_with'>zip_with</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='comma'>,</span> <span class='id identifier rubyid_op'>op</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
521
|
-
<span class='kw'>return</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_empty?'>empty?</span> <span class='op'>||</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
522
|
-
|
523
|
-
<span class='id identifier rubyid_clipped'>clipped</span> <span class='op'>=</span> <span class='kw'>self</span><span class='lbracket'>[</span><span class='int'>0</span><span class='op'>..</span><span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>-</span> <span class='int'>1</span><span class='rbracket'>]</span>
|
524
|
-
<span class='id identifier rubyid_zipped'>zipped</span> <span class='op'>=</span> <span class='id identifier rubyid_clipped'>clipped</span><span class='period'>.</span><span class='id identifier rubyid_zip'>zip</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
|
525
|
-
|
526
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_op'>op</span>
|
527
|
-
<span class='id identifier rubyid_zipped'>zipped</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='op'>|</span> <span class='id identifier rubyid_a'>a</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_op'>op</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
528
|
-
<span class='kw'>else</span>
|
529
|
-
<span class='id identifier rubyid_zipped'>zipped</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='op'>|</span> <span class='kw'>yield</span><span class='lparen'>(</span><span class='id identifier rubyid_a'>a</span><span class='comma'>,</span> <span class='id identifier rubyid_b'>b</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
530
|
-
<span class='kw'>end</span>
|
531
|
-
<span class='kw'>end</span></pre>
|
532
|
-
</td>
|
533
|
-
</tr>
|
534
|
-
</table>
|
535
|
-
</div>
|
536
|
-
|
537
|
-
</div>
|
538
|
-
|
539
|
-
</div>
|
540
|
-
|
541
|
-
<div id="footer">
|
542
|
-
Generated on Tue May 5 19:54:28 2020 by
|
543
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
544
|
-
0.9.24 (ruby-2.7.1).
|
545
|
-
</div>
|
546
|
-
|
547
|
-
</div>
|
548
|
-
</body>
|
549
|
-
</html>
|