shenanigans 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Array.html +20 -6
- data/doc/Fixnum.html +11 -3
- data/doc/Hash.html +26 -11
- data/doc/Kernel.html +75 -13
- data/doc/Module.html +208 -0
- data/doc/Object.html +20 -7
- data/doc/README_rdoc.html +31 -12
- data/doc/String.html +12 -4
- data/doc/created.rid +25 -22
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/index.html +15 -14
- data/doc/js/darkfish.js +9 -7
- data/doc/js/search_index.js +1 -1
- data/doc/rdoc.css +52 -0
- data/doc/table_of_contents.html +8 -1
- data/lib/shenanigans/kernel.rb +1 -0
- data/lib/shenanigans/kernel/fn.rb +2 -0
- data/lib/shenanigans/kernel/prompt.rb +1 -0
- data/lib/shenanigans/kernel/require_optional.rb +19 -0
- data/lib/shenanigans/kernel/with.rb +2 -0
- data/lib/shenanigans/module/private_accessor.rb +4 -2
- data/test/kernel/test_require_optional.rb +17 -0
- metadata +7 -3
- data/lib/shenanigans/README.mdown +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c51ac956ec8c326d6f7bbb962d1c226df339a93
|
4
|
+
data.tar.gz: d1300bab95b3c6f7d103f384968459cbd8675aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1662c5ccfbe51264f092d8aa104ff1db3a2085ab7724d750cc92a3e42c39d404c95d344f064f80afc7c1daba80d4ba81d6d582d6b654ae0fa5f1ffbea9c0a9df
|
7
|
+
data.tar.gz: 3ddb1d799672c6a8e08b70a2cbbc2bc612969dc5f954fd6686986e75e5cc2bcaa8ba330489f168e09ceb453bb24268d592f5d0b28480c5c92e9a97e18e2e8099
|
data/doc/Array.html
CHANGED
@@ -43,6 +43,8 @@
|
|
43
43
|
</nav>
|
44
44
|
|
45
45
|
|
46
|
+
|
47
|
+
|
46
48
|
<div id="file-metadata">
|
47
49
|
<nav id="file-list-section" class="section">
|
48
50
|
<h3 class="section-header">Defined In</h3>
|
@@ -66,17 +68,18 @@
|
|
66
68
|
</nav>
|
67
69
|
|
68
70
|
|
71
|
+
|
69
72
|
<!-- Method Quickref -->
|
70
73
|
<nav id="method-list-section" class="section">
|
71
74
|
<h3 class="section-header">Methods</h3>
|
72
75
|
|
73
76
|
<ul class="link-list">
|
74
77
|
|
75
|
-
<li><a href="#method-i-5E">#^</a>
|
78
|
+
<li ><a href="#method-i-5E">#^</a>
|
76
79
|
|
77
|
-
<li><a href="#method-i-random_subarray">#random_subarray</a>
|
80
|
+
<li ><a href="#method-i-random_subarray">#random_subarray</a>
|
78
81
|
|
79
|
-
<li><a href="#method-i-zip_with">#zip_with</a>
|
82
|
+
<li ><a href="#method-i-zip_with">#zip_with</a>
|
80
83
|
|
81
84
|
</ul>
|
82
85
|
</nav>
|
@@ -107,6 +110,8 @@
|
|
107
110
|
|
108
111
|
<li><a href="./Kernel.html">Kernel</a>
|
109
112
|
|
113
|
+
<li><a href="./Module.html">Module</a>
|
114
|
+
|
110
115
|
<li><a href="./Object.html">Object</a>
|
111
116
|
|
112
117
|
<li><a href="./String.html">String</a>
|
@@ -147,7 +152,9 @@
|
|
147
152
|
<div class="method-heading">
|
148
153
|
<span class="method-name">^</span><span
|
149
154
|
class="method-args">(other)</span>
|
155
|
+
|
150
156
|
<span class="method-click-advice">click to toggle source</span>
|
157
|
+
|
151
158
|
</div>
|
152
159
|
|
153
160
|
|
@@ -159,6 +166,7 @@
|
|
159
166
|
<span class="ruby-comment">#=> [3, 4]</span>
|
160
167
|
</pre>
|
161
168
|
|
169
|
+
|
162
170
|
|
163
171
|
|
164
172
|
<div class="method-source-code" id="5E-source">
|
@@ -181,7 +189,9 @@
|
|
181
189
|
<div class="method-heading">
|
182
190
|
<span class="method-name">random_subarray</span><span
|
183
191
|
class="method-args">(n=1)</span>
|
192
|
+
|
184
193
|
<span class="method-click-advice">click to toggle source</span>
|
194
|
+
|
185
195
|
</div>
|
186
196
|
|
187
197
|
|
@@ -190,11 +200,12 @@
|
|
190
200
|
<p>Generates random subarrays. Uses random numbers and bit-fiddling to assure
|
191
201
|
performant uniform distributions even for large arrays.</p>
|
192
202
|
|
193
|
-
<pre class="ruby"><span class="ruby-identifier">a</span> =
|
203
|
+
<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-operator">*</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">5</span>
|
194
204
|
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">random_subarray</span>(<span class="ruby-value">3</span>)
|
195
205
|
<span class="ruby-comment">#=> [[1, 3, 5], [2, 4], [1, 3, 4, 5]]</span>
|
196
206
|
</pre>
|
197
207
|
|
208
|
+
|
198
209
|
|
199
210
|
|
200
211
|
<div class="method-source-code" id="random_subarray-source">
|
@@ -221,7 +232,9 @@ performant uniform distributions even for large arrays.</p>
|
|
221
232
|
<div class="method-heading">
|
222
233
|
<span class="method-name">zip_with</span><span
|
223
234
|
class="method-args">(other, op=nil) { |a, b| ... }</span>
|
235
|
+
|
224
236
|
<span class="method-click-advice">click to toggle source</span>
|
237
|
+
|
225
238
|
</div>
|
226
239
|
|
227
240
|
|
@@ -239,10 +252,11 @@ shorter of the two arrays.</p>
|
|
239
252
|
|
240
253
|
<p>For more complex combinations, a block can be provided:</p>
|
241
254
|
|
242
|
-
<pre class="ruby">[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>].<span class="ruby-identifier">zip_with</span>([<span class="ruby-value">6</span>,<span class="ruby-value">5</span>,<span class="ruby-value">4</span>]) { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,<span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-value">3</span
|
255
|
+
<pre class="ruby">[<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">3</span>].<span class="ruby-identifier">zip_with</span>([<span class="ruby-value">6</span>,<span class="ruby-value">5</span>,<span class="ruby-value">4</span>]) { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,<span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-value">3</span><span class="ruby-operator">*</span><span class="ruby-identifier">a</span><span class="ruby-operator">+</span><span class="ruby-value">2</span><span class="ruby-operator">*</span><span class="ruby-identifier">b</span> }
|
243
256
|
<span class="ruby-comment">#=> [15, 16, 17]</span>
|
244
257
|
</pre>
|
245
258
|
|
259
|
+
|
246
260
|
|
247
261
|
|
248
262
|
<div class="method-source-code" id="zip_with-source">
|
@@ -277,7 +291,7 @@ shorter of the two arrays.</p>
|
|
277
291
|
|
278
292
|
<footer id="validator-badges">
|
279
293
|
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
280
|
-
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a>
|
294
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
281
295
|
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
282
296
|
</footer>
|
283
297
|
|
data/doc/Fixnum.html
CHANGED
@@ -43,6 +43,8 @@
|
|
43
43
|
</nav>
|
44
44
|
|
45
45
|
|
46
|
+
|
47
|
+
|
46
48
|
<div id="file-metadata">
|
47
49
|
<nav id="file-list-section" class="section">
|
48
50
|
<h3 class="section-header">Defined In</h3>
|
@@ -64,13 +66,14 @@
|
|
64
66
|
</nav>
|
65
67
|
|
66
68
|
|
69
|
+
|
67
70
|
<!-- Method Quickref -->
|
68
71
|
<nav id="method-list-section" class="section">
|
69
72
|
<h3 class="section-header">Methods</h3>
|
70
73
|
|
71
74
|
<ul class="link-list">
|
72
75
|
|
73
|
-
<li><a href="#method-i-string_length">#string_length</a>
|
76
|
+
<li ><a href="#method-i-string_length">#string_length</a>
|
74
77
|
|
75
78
|
</ul>
|
76
79
|
</nav>
|
@@ -101,6 +104,8 @@
|
|
101
104
|
|
102
105
|
<li><a href="./Kernel.html">Kernel</a>
|
103
106
|
|
107
|
+
<li><a href="./Module.html">Module</a>
|
108
|
+
|
104
109
|
<li><a href="./Object.html">Object</a>
|
105
110
|
|
106
111
|
<li><a href="./String.html">String</a>
|
@@ -141,13 +146,15 @@
|
|
141
146
|
<div class="method-heading">
|
142
147
|
<span class="method-name">string_length</span><span
|
143
148
|
class="method-args">()</span>
|
149
|
+
|
144
150
|
<span class="method-click-advice">click to toggle source</span>
|
151
|
+
|
145
152
|
</div>
|
146
153
|
|
147
154
|
|
148
155
|
<div class="method-description">
|
149
156
|
|
150
|
-
<p>Returns the length of the number
|
157
|
+
<p>Returns the length of the number's string representation.</p>
|
151
158
|
|
152
159
|
<pre class="ruby"><span class="ruby-value">0</span>.<span class="ruby-identifier">string_length</span>
|
153
160
|
<span class="ruby-comment">#=> 1</span>
|
@@ -157,6 +164,7 @@
|
|
157
164
|
<span class="ruby-comment">#=> 2</span>
|
158
165
|
</pre>
|
159
166
|
|
167
|
+
|
160
168
|
|
161
169
|
|
162
170
|
<div class="method-source-code" id="string_length-source">
|
@@ -185,7 +193,7 @@
|
|
185
193
|
|
186
194
|
<footer id="validator-badges">
|
187
195
|
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
188
|
-
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a>
|
196
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
189
197
|
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
190
198
|
</footer>
|
191
199
|
|
data/doc/Hash.html
CHANGED
@@ -43,6 +43,8 @@
|
|
43
43
|
</nav>
|
44
44
|
|
45
45
|
|
46
|
+
|
47
|
+
|
46
48
|
<div id="file-metadata">
|
47
49
|
<nav id="file-list-section" class="section">
|
48
50
|
<h3 class="section-header">Defined In</h3>
|
@@ -66,17 +68,18 @@
|
|
66
68
|
</nav>
|
67
69
|
|
68
70
|
|
71
|
+
|
69
72
|
<!-- Method Quickref -->
|
70
73
|
<nav id="method-list-section" class="section">
|
71
74
|
<h3 class="section-header">Methods</h3>
|
72
75
|
|
73
76
|
<ul class="link-list">
|
74
77
|
|
75
|
-
<li><a href="#method-i-extract">#extract</a>
|
78
|
+
<li ><a href="#method-i-extract">#extract</a>
|
76
79
|
|
77
|
-
<li><a href="#method-i-has_shape-3F">#has_shape?</a>
|
80
|
+
<li ><a href="#method-i-has_shape-3F">#has_shape?</a>
|
78
81
|
|
79
|
-
<li><a href="#method-i-to_ostruct">#to_ostruct</a>
|
82
|
+
<li ><a href="#method-i-to_ostruct">#to_ostruct</a>
|
80
83
|
|
81
84
|
</ul>
|
82
85
|
</nav>
|
@@ -107,6 +110,8 @@
|
|
107
110
|
|
108
111
|
<li><a href="./Kernel.html">Kernel</a>
|
109
112
|
|
113
|
+
<li><a href="./Module.html">Module</a>
|
114
|
+
|
110
115
|
<li><a href="./Object.html">Object</a>
|
111
116
|
|
112
117
|
<li><a href="./String.html">String</a>
|
@@ -147,7 +152,9 @@
|
|
147
152
|
<div class="method-heading">
|
148
153
|
<span class="method-name">extract</span><span
|
149
154
|
class="method-args">(*ks)</span>
|
155
|
+
|
150
156
|
<span class="method-click-advice">click to toggle source</span>
|
157
|
+
|
151
158
|
</div>
|
152
159
|
|
153
160
|
|
@@ -162,13 +169,14 @@
|
|
162
169
|
<span class="ruby-comment">#=> { a: 1}</span>
|
163
170
|
</pre>
|
164
171
|
|
172
|
+
|
165
173
|
|
166
174
|
|
167
175
|
<div class="method-source-code" id="extract-source">
|
168
176
|
<pre><span class="ruby-comment"># File lib/shenanigans/hash/extract.rb, line 8</span>
|
169
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">extract</span>(
|
170
|
-
<span class="ruby-identifier">existing</span> = <span class="ruby-identifier">keys</span>
|
171
|
-
<span class="ruby-constant">Hash</span>[<span class="ruby-identifier">existing</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">values_at</span>(
|
177
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">extract</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">ks</span>)
|
178
|
+
<span class="ruby-identifier">existing</span> = <span class="ruby-identifier">keys</span> <span class="ruby-operator">&</span> <span class="ruby-identifier">ks</span>
|
179
|
+
<span class="ruby-constant">Hash</span>[<span class="ruby-identifier">existing</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">values_at</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">existing</span>))]
|
172
180
|
<span class="ruby-keyword">end</span></pre>
|
173
181
|
</div><!-- extract-source -->
|
174
182
|
|
@@ -185,7 +193,9 @@
|
|
185
193
|
<div class="method-heading">
|
186
194
|
<span class="method-name">has_shape?</span><span
|
187
195
|
class="method-args">(shape)</span>
|
196
|
+
|
188
197
|
<span class="method-click-advice">click to toggle source</span>
|
198
|
+
|
189
199
|
</div>
|
190
200
|
|
191
201
|
|
@@ -208,6 +218,7 @@
|
|
208
218
|
<span class="ruby-comment">#=> true</span>
|
209
219
|
</pre>
|
210
220
|
|
221
|
+
|
211
222
|
|
212
223
|
|
213
224
|
<div class="method-source-code" id="has_shape-3F-source">
|
@@ -232,7 +243,9 @@
|
|
232
243
|
<div class="method-heading">
|
233
244
|
<span class="method-name">to_ostruct</span><span
|
234
245
|
class="method-args">()</span>
|
246
|
+
|
235
247
|
<span class="method-click-advice">click to toggle source</span>
|
248
|
+
|
236
249
|
</div>
|
237
250
|
|
238
251
|
|
@@ -241,7 +254,8 @@
|
|
241
254
|
<p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es
|
242
255
|
to <code>OpenStruct</code>s. Especially useful for parsing YAML.</p>
|
243
256
|
|
244
|
-
<pre class="ruby"><span class="ruby-identifier">yaml</span>=<span class="ruby-
|
257
|
+
<pre class="ruby"><span class="ruby-identifier">yaml</span>=<span class="ruby-value"><<EOY
|
258
|
+
subject: Programming Languages
|
245
259
|
languages:
|
246
260
|
- name : Ruby
|
247
261
|
creator : Matz
|
@@ -249,7 +263,7 @@ languages:
|
|
249
263
|
creator : Guido van Rossum
|
250
264
|
- name : Perl
|
251
265
|
creator : Larry Wall
|
252
|
-
|
266
|
+
EOY</span>
|
253
267
|
<span class="ruby-identifier">struct</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">yaml</span>).<span class="ruby-identifier">to_ostruct</span>
|
254
268
|
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">subject</span>
|
255
269
|
<span class="ruby-comment">#=> "Programming Languages"</span>
|
@@ -259,6 +273,7 @@ languages:
|
|
259
273
|
<span class="ruby-comment">#=> "Matz"</span>
|
260
274
|
</pre>
|
261
275
|
|
276
|
+
|
262
277
|
|
263
278
|
|
264
279
|
<div class="method-source-code" id="to_ostruct-source">
|
@@ -269,12 +284,12 @@ languages:
|
|
269
284
|
<span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>
|
270
285
|
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_ostruct</span>]
|
271
286
|
<span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span>
|
272
|
-
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">el</span><span class="ruby-operator">|</span> <span class="ruby-
|
287
|
+
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">el</span><span class="ruby-operator">|</span> <span class="ruby-identifier">el</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_ostruct</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">el</span>.<span class="ruby-identifier">to_ostruct</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">el</span> }]
|
273
288
|
<span class="ruby-keyword">else</span>
|
274
289
|
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>]
|
275
290
|
<span class="ruby-keyword">end</span>
|
276
291
|
<span class="ruby-keyword">end</span>
|
277
|
-
<span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arr</span>)
|
292
|
+
<span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Hash</span>[<span class="ruby-identifier">arr</span>])
|
278
293
|
<span class="ruby-keyword">end</span></pre>
|
279
294
|
</div><!-- to_ostruct-source -->
|
280
295
|
|
@@ -295,7 +310,7 @@ languages:
|
|
295
310
|
|
296
311
|
<footer id="validator-badges">
|
297
312
|
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
298
|
-
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a>
|
313
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
299
314
|
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
300
315
|
</footer>
|
301
316
|
|
data/doc/Kernel.html
CHANGED
@@ -43,12 +43,15 @@
|
|
43
43
|
</nav>
|
44
44
|
|
45
45
|
|
46
|
+
|
47
|
+
|
46
48
|
<div id="file-metadata">
|
47
49
|
<nav id="file-list-section" class="section">
|
48
50
|
<h3 class="section-header">Defined In</h3>
|
49
51
|
<ul>
|
50
52
|
<li>lib/shenanigans/kernel/fn.rb
|
51
53
|
<li>lib/shenanigans/kernel/prompt.rb
|
54
|
+
<li>lib/shenanigans/kernel/require_optional.rb
|
52
55
|
<li>lib/shenanigans/kernel/with.rb
|
53
56
|
</ul>
|
54
57
|
</nav>
|
@@ -60,17 +63,20 @@
|
|
60
63
|
|
61
64
|
|
62
65
|
|
66
|
+
|
63
67
|
<!-- Method Quickref -->
|
64
68
|
<nav id="method-list-section" class="section">
|
65
69
|
<h3 class="section-header">Methods</h3>
|
66
70
|
|
67
71
|
<ul class="link-list">
|
68
72
|
|
69
|
-
<li><a href="#method-i-fn">#fn</a>
|
73
|
+
<li ><a href="#method-i-fn">#fn</a>
|
70
74
|
|
71
|
-
<li><a href="#method-i-prompt">#prompt</a>
|
75
|
+
<li ><a href="#method-i-prompt">#prompt</a>
|
72
76
|
|
73
|
-
<li><a href="#method-i-
|
77
|
+
<li ><a href="#method-i-require_optional">#require_optional</a>
|
78
|
+
|
79
|
+
<li ><a href="#method-i-with">#with</a>
|
74
80
|
|
75
81
|
</ul>
|
76
82
|
</nav>
|
@@ -101,6 +107,8 @@
|
|
101
107
|
|
102
108
|
<li><a href="./Kernel.html">Kernel</a>
|
103
109
|
|
110
|
+
<li><a href="./Module.html">Module</a>
|
111
|
+
|
104
112
|
<li><a href="./Object.html">Object</a>
|
105
113
|
|
106
114
|
<li><a href="./String.html">String</a>
|
@@ -147,8 +155,8 @@
|
|
147
155
|
|
148
156
|
<!-- Methods -->
|
149
157
|
|
150
|
-
<section id="
|
151
|
-
<h3 class="section-header">
|
158
|
+
<section id="private-instance-5Buntitled-5D-method-details" class="method-section section">
|
159
|
+
<h3 class="section-header">Private Instance Methods</h3>
|
152
160
|
|
153
161
|
|
154
162
|
<div id="method-i-fn" class="method-detail ">
|
@@ -156,7 +164,9 @@
|
|
156
164
|
<div class="method-heading">
|
157
165
|
<span class="method-name">fn</span><span
|
158
166
|
class="method-args">(*funs)</span>
|
167
|
+
|
159
168
|
<span class="method-click-advice">click to toggle source</span>
|
169
|
+
|
160
170
|
</div>
|
161
171
|
|
162
172
|
|
@@ -165,18 +175,19 @@
|
|
165
175
|
<p>Composes a list of functions. Functions can be specified as symbols or
|
166
176
|
lambdas.</p>
|
167
177
|
|
168
|
-
<pre class="ruby">[<span class="ruby-string">"foo bar"</span>, <span class="ruby-string">"baz qux"</span>].<span class="ruby-identifier">map</span>
|
178
|
+
<pre class="ruby">[<span class="ruby-string">"foo bar"</span>, <span class="ruby-string">"baz qux"</span>].<span class="ruby-identifier">map</span> <span class="ruby-operator">&</span><span class="ruby-identifier">fn</span>(:<span class="ruby-identifier">split</span>, :<span class="ruby-identifier">last</span>)
|
169
179
|
<span class="ruby-comment">#=> ["bar", "qux"]</span>
|
170
180
|
|
171
|
-
(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>).<span class="ruby-identifier">map</span>
|
181
|
+
(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>).<span class="ruby-identifier">map</span> <span class="ruby-operator">&</span><span class="ruby-identifier">fn</span>(:<span class="ruby-keyword">next</span>, <span class="ruby-operator">-</span><span class="ruby-operator">></span> <span class="ruby-identifier">x</span> { <span class="ruby-identifier">x</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">x</span> }, <span class="ruby-operator">-</span><span class="ruby-operator">></span> <span class="ruby-identifier">x</span> { <span class="ruby-identifier">x</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">2</span> } )
|
172
182
|
<span class="ruby-comment">#=> [2.0, 4.5, 8.0]</span>
|
173
183
|
</pre>
|
174
184
|
|
185
|
+
|
175
186
|
|
176
187
|
|
177
188
|
<div class="method-source-code" id="fn-source">
|
178
189
|
<pre><span class="ruby-comment"># File lib/shenanigans/kernel/fn.rb, line 9</span>
|
179
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fn</span>(
|
190
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">fn</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">funs</span>)
|
180
191
|
<span class="ruby-operator">-</span><span class="ruby-operator">></span> <span class="ruby-identifier">x</span> <span class="ruby-keyword">do</span>
|
181
192
|
<span class="ruby-identifier">funs</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-identifier">x</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">v</span>,<span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
|
182
193
|
<span class="ruby-constant">Proc</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">f</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">v</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">f</span>)
|
@@ -198,7 +209,9 @@ lambdas.</p>
|
|
198
209
|
<div class="method-heading">
|
199
210
|
<span class="method-name">prompt</span><span
|
200
211
|
class="method-args">(text='', conversion=nil)</span>
|
212
|
+
|
201
213
|
<span class="method-click-advice">click to toggle source</span>
|
214
|
+
|
202
215
|
</div>
|
203
216
|
|
204
217
|
|
@@ -217,11 +230,12 @@ conversion method.</p>
|
|
217
230
|
<span class="ruby-comment">#=> 12.0</span>
|
218
231
|
</pre>
|
219
232
|
|
233
|
+
|
220
234
|
|
221
235
|
|
222
236
|
<div class="method-source-code" id="prompt-source">
|
223
237
|
<pre><span class="ruby-comment"># File lib/shenanigans/kernel/prompt.rb, line 17</span>
|
224
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prompt</span>(<span class="ruby-identifier">text</span>=<span class="ruby-string"
|
238
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prompt</span>(<span class="ruby-identifier">text</span>=<span class="ruby-string">''</span>, <span class="ruby-identifier">conversion</span>=<span class="ruby-keyword">nil</span>)
|
225
239
|
<span class="ruby-identifier">print</span> <span class="ruby-identifier">text</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">empty?</span>
|
226
240
|
<span class="ruby-identifier">input</span> = <span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span>
|
227
241
|
<span class="ruby-constant">CONVERSIONS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">conversion</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">input</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">conversion</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">input</span>
|
@@ -236,12 +250,59 @@ conversion method.</p>
|
|
236
250
|
</div><!-- prompt-method -->
|
237
251
|
|
238
252
|
|
253
|
+
<div id="method-i-require_optional" class="method-detail ">
|
254
|
+
|
255
|
+
<div class="method-heading">
|
256
|
+
<span class="method-name">require_optional</span><span
|
257
|
+
class="method-args">(gem, &block)</span>
|
258
|
+
|
259
|
+
<span class="method-click-advice">click to toggle source</span>
|
260
|
+
|
261
|
+
</div>
|
262
|
+
|
263
|
+
|
264
|
+
<div class="method-description">
|
265
|
+
|
266
|
+
<p>Optionally require a gem. If it is not available, <code>nil</code> will be
|
267
|
+
returned. Alternatively, a block can be provided with code to run.</p>
|
268
|
+
|
269
|
+
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'non_existent'</span>
|
270
|
+
<span class="ruby-comment">#=> nil</span>
|
271
|
+
|
272
|
+
<span class="ruby-identifier">require</span> <span class="ruby-string">'non_existent'</span> <span class="ruby-keyword">do</span>
|
273
|
+
<span class="ruby-identifier">puts</span> <span class="ruby-string">'Something went wrong'</span>
|
274
|
+
<span class="ruby-keyword">end</span>
|
275
|
+
<span class="ruby-comment">#=> Outputs 'Something went wrong'</span>
|
276
|
+
</pre>
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
<div class="method-source-code" id="require_optional-source">
|
282
|
+
<pre><span class="ruby-comment"># File lib/shenanigans/kernel/require_optional.rb, line 12</span>
|
283
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">require_optional</span>(<span class="ruby-identifier">gem</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
284
|
+
<span class="ruby-identifier">require</span> <span class="ruby-identifier">gem</span>
|
285
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">LoadError</span>
|
286
|
+
<span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>
|
287
|
+
<span class="ruby-keyword">end</span></pre>
|
288
|
+
</div><!-- require_optional-source -->
|
289
|
+
|
290
|
+
</div>
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
</div><!-- require_optional-method -->
|
296
|
+
|
297
|
+
|
239
298
|
<div id="method-i-with" class="method-detail ">
|
240
299
|
|
241
300
|
<div class="method-heading">
|
242
301
|
<span class="method-name">with</span><span
|
243
302
|
class="method-args">(o, &blk)</span>
|
303
|
+
|
244
304
|
<span class="method-click-advice">click to toggle source</span>
|
305
|
+
|
245
306
|
</div>
|
246
307
|
|
247
308
|
|
@@ -257,12 +318,13 @@ the provided block and then returns it.</p>
|
|
257
318
|
<span class="ruby-comment">#=> ["a", "b"]</span>
|
258
319
|
</pre>
|
259
320
|
|
321
|
+
|
260
322
|
|
261
323
|
|
262
324
|
<div class="method-source-code" id="with-source">
|
263
325
|
<pre><span class="ruby-comment"># File lib/shenanigans/kernel/with.rb, line 9</span>
|
264
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">with</span>(<span class="ruby-identifier">o</span>,
|
265
|
-
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">tap</span>(
|
326
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">with</span>(<span class="ruby-identifier">o</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
327
|
+
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">tap</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
|
266
328
|
<span class="ruby-keyword">end</span></pre>
|
267
329
|
</div><!-- with-source -->
|
268
330
|
|
@@ -274,7 +336,7 @@ the provided block and then returns it.</p>
|
|
274
336
|
</div><!-- with-method -->
|
275
337
|
|
276
338
|
|
277
|
-
</section><!--
|
339
|
+
</section><!-- private-instance-method-details -->
|
278
340
|
|
279
341
|
</section><!-- 5Buntitled-5D -->
|
280
342
|
|
@@ -283,7 +345,7 @@ the provided block and then returns it.</p>
|
|
283
345
|
|
284
346
|
<footer id="validator-badges">
|
285
347
|
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
286
|
-
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a>
|
348
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
287
349
|
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
288
350
|
</footer>
|
289
351
|
|