shenanigans 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Gemfile +5 -0
  2. data/LICENSE +7 -0
  3. data/README.rdoc +57 -0
  4. data/doc/Array.html +240 -0
  5. data/doc/Kernel.html +283 -0
  6. data/doc/Object.html +179 -0
  7. data/doc/README_rdoc.html +174 -0
  8. data/doc/created.rid +12 -0
  9. data/doc/images/add.png +0 -0
  10. data/doc/images/brick.png +0 -0
  11. data/doc/images/brick_link.png +0 -0
  12. data/doc/images/bug.png +0 -0
  13. data/doc/images/bullet_black.png +0 -0
  14. data/doc/images/bullet_toggle_minus.png +0 -0
  15. data/doc/images/bullet_toggle_plus.png +0 -0
  16. data/doc/images/date.png +0 -0
  17. data/doc/images/delete.png +0 -0
  18. data/doc/images/find.png +0 -0
  19. data/doc/images/loadingAnimation.gif +0 -0
  20. data/doc/images/macFFBgHack.png +0 -0
  21. data/doc/images/package.png +0 -0
  22. data/doc/images/page_green.png +0 -0
  23. data/doc/images/page_white_text.png +0 -0
  24. data/doc/images/page_white_width.png +0 -0
  25. data/doc/images/plugin.png +0 -0
  26. data/doc/images/ruby.png +0 -0
  27. data/doc/images/tag_blue.png +0 -0
  28. data/doc/images/tag_green.png +0 -0
  29. data/doc/images/transparent.png +0 -0
  30. data/doc/images/wrench.png +0 -0
  31. data/doc/images/wrench_orange.png +0 -0
  32. data/doc/images/zoom.png +0 -0
  33. data/doc/index.html +173 -0
  34. data/doc/js/darkfish.js +153 -0
  35. data/doc/js/jquery.js +18 -0
  36. data/doc/js/navigation.js +142 -0
  37. data/doc/js/search.js +94 -0
  38. data/doc/js/search_index.js +1 -0
  39. data/doc/js/searcher.js +228 -0
  40. data/doc/rdoc.css +543 -0
  41. data/doc/table_of_contents.html +82 -0
  42. data/lib/shenanigans/README.mdown +57 -0
  43. data/lib/shenanigans/array/random_subarray.rb +16 -0
  44. data/lib/shenanigans/array/zip_with.rb +27 -0
  45. data/lib/shenanigans/array.rb +2 -0
  46. data/lib/shenanigans/kernel/fn.rb +16 -0
  47. data/lib/shenanigans/kernel/prompt.rb +23 -0
  48. data/lib/shenanigans/kernel/with.rb +12 -0
  49. data/lib/shenanigans/kernel.rb +3 -0
  50. data/lib/shenanigans/object/identity.rb +9 -0
  51. data/lib/shenanigans/object.rb +1 -0
  52. data/lib/shenanigans/shenanigans-0.0.1.gem +0 -0
  53. data/lib/shenanigans.rb +3 -0
  54. data/test/array/test_random_subarray.rb +10 -0
  55. data/test/array/test_zip_with.rb +14 -0
  56. data/test/kernel/test_fn.rb +14 -0
  57. data/test/kernel/test_prompt.rb +27 -0
  58. data/test/kernel/test_with.rb +12 -0
  59. data/test/object/test_identity.rb +9 -0
  60. metadata +103 -0
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem "rake"
4
+ gem "minitest", ">= 2.6.0", :group => :development
5
+ gem "rdoc", :group => :development
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Michael Kohl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ = Shenanigans
2
+
3
+ *shenanigan* (plural shenanigans):
4
+
5
+ 1. Trickery, games; skulduggery. To "call", "claim" or "declare" shenanigans is to rhetorically label something as officially deceitful, improper, or otherwise incorrect. <em>"The advertisement said it would cost $50 but they charged me $75 at the register. I declare shenanigans."</em> The speaker passes off the statement as having some sort of implied official effect, but in reality, it is simply a complaint.
6
+
7
+ 2. A deceitful confidence trick, or mischief causing discomfort or annoyance. <em>You should learn to spot their shenanigans and avoid being fooled.</em>
8
+
9
+ 3. Mischievous play, especially by children.
10
+
11
+ Source: {Wiktionary}[http://en.wiktionary.org/wiki/shenanigan#English]
12
+
13
+ == Introduction
14
+
15
+ Ruby Facets is the premiere collection of general purpose method
16
+ extensions and standard additions for the Ruby programming language. This is not Ruby Facets though, so what you get is a random collection of methods I wrote because I found them interesting and/or useful. Some of them I actually also contributed to Facets, although sometimes they have different names or slightly different implementations.
17
+
18
+ == Installation
19
+
20
+ Shenanigans can be installed via {RubyGems}[http://rubygems.org/].
21
+
22
+ $ gem install shenanigans
23
+
24
+ I only works on 1.9.3 and I generally only test it with the most current Ruby release.
25
+
26
+
27
+ == Usage
28
+
29
+ If you really want the whole shebang, you can get it this way:
30
+
31
+ require 'shenanigans'
32
+
33
+ Requiring a single method works as follows:
34
+
35
+ require 'shenanigans/<class|module>/<method>'
36
+
37
+ Requiring all the extensions of a class or module also works:
38
+
39
+ require 'shenanigans/kernel'
40
+
41
+ == Contribute
42
+
43
+ If you have something you want to contribute to Shenanigans, you shoud reconsider and add it to Facets instead. This is a library for my own wonky ideas and I don't think it will ever see any real usage.
44
+
45
+ == Authors
46
+
47
+ This project was created by Michael Kohl. He can be reached via email at citizen428 at gmail.com.
48
+
49
+ == License
50
+
51
+ Copyright (c) 2012 Michael Kohl
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/doc/Array.html ADDED
@@ -0,0 +1,240 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>class Array - Shenanigans</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="class">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/shenanigans/array/random_subarray.rb
51
+ <li>lib/shenanigans/array/zip_with.rb
52
+ </ul>
53
+ </nav>
54
+
55
+
56
+ </div>
57
+
58
+ <div id="class-metadata">
59
+
60
+ <nav id="parent-class-section" class="section">
61
+ <h3 class="section-header">Parent</h3>
62
+
63
+ <p class="link"><a href="Object.html">Object</a>
64
+
65
+ </nav>
66
+
67
+
68
+ <!-- Method Quickref -->
69
+ <nav id="method-list-section" class="section">
70
+ <h3 class="section-header">Methods</h3>
71
+
72
+ <ul class="link-list">
73
+
74
+ <li><a href="#method-i-random_subarray">#random_subarray</a>
75
+
76
+ <li><a href="#method-i-zip_with">#zip_with</a>
77
+
78
+ </ul>
79
+ </nav>
80
+
81
+ </div>
82
+
83
+ <div id="project-metadata">
84
+ <nav id="fileindex-section" class="section project-section">
85
+ <h3 class="section-header">Pages</h3>
86
+
87
+ <ul>
88
+
89
+ <li class="file"><a href="./README_rdoc.html">README</a>
90
+
91
+ </ul>
92
+ </nav>
93
+
94
+ <nav id="classindex-section" class="section project-section">
95
+ <h3 class="section-header">Class and Module Index</h3>
96
+
97
+ <ul class="link-list">
98
+
99
+ <li><a href="./Array.html">Array</a>
100
+
101
+ <li><a href="./Kernel.html">Kernel</a>
102
+
103
+ <li><a href="./Object.html">Object</a>
104
+
105
+ </ul>
106
+ </nav>
107
+
108
+ </div>
109
+ </nav>
110
+
111
+ <div id="documentation">
112
+ <h1 class="class">class Array</h1>
113
+
114
+ <div id="description" class="description">
115
+
116
+ </div><!-- description -->
117
+
118
+
119
+
120
+
121
+ <section id="5Buntitled-5D" class="documentation-section">
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+ <!-- Methods -->
131
+
132
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
133
+ <h3 class="section-header">Public Instance Methods</h3>
134
+
135
+
136
+ <div id="method-i-random_subarray" class="method-detail ">
137
+
138
+ <div class="method-heading">
139
+ <span class="method-name">random_subarray</span><span
140
+ class="method-args">(n=1)</span>
141
+ <span class="method-click-advice">click to toggle source</span>
142
+ </div>
143
+
144
+
145
+ <div class="method-description">
146
+
147
+ <p>Generates random subarrays. Uses random numbers and bit-fiddling to assure
148
+ performant uniform distributions even for large arrays.</p>
149
+
150
+ <pre class="ruby"><span class="ruby-identifier">a</span> = *<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">5</span>
151
+ <span class="ruby-identifier">a</span>.<span class="ruby-identifier">random_subarray</span>(<span class="ruby-value">3</span>)
152
+ <span class="ruby-comment">#=&gt; [[1, 3, 5], [2, 4], [1, 3, 4, 5]]</span>
153
+ </pre>
154
+
155
+
156
+
157
+ <div class="method-source-code" id="random_subarray-source">
158
+ <pre><span class="ruby-comment"># File lib/shenanigans/array/random_subarray.rb, line 9</span>
159
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">random_subarray</span>(<span class="ruby-identifier">n</span>=<span class="ruby-value">1</span>)
160
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">&quot;negative argument&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
161
+ (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">n</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span>
162
+ <span class="ruby-identifier">r</span> = <span class="ruby-identifier">rand</span>(<span class="ruby-value">2</span><span class="ruby-operator">**</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">size</span>)
163
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">select</span>.<span class="ruby-identifier">with_index</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span> }
164
+ <span class="ruby-keyword">end</span>
165
+ <span class="ruby-keyword">end</span></pre>
166
+ </div><!-- random_subarray-source -->
167
+
168
+ </div>
169
+
170
+
171
+
172
+
173
+ </div><!-- random_subarray-method -->
174
+
175
+
176
+ <div id="method-i-zip_with" class="method-detail ">
177
+
178
+ <div class="method-heading">
179
+ <span class="method-name">zip_with</span><span
180
+ class="method-args">(other, op=nil) { |a, b| ... }</span>
181
+ <span class="method-click-advice">click to toggle source</span>
182
+ </div>
183
+
184
+
185
+ <div class="method-description">
186
+
187
+ <p>Zip <code>self</code> with <code>other</code>, combining the elements with
188
+ the provided block or symbol. The resulting array will be as long as the
189
+ shorter of the two arrays.</p>
190
+
191
+ <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>)
192
+ <span class="ruby-comment">#=&gt; [7, 7, 7]</span>
193
+ <span class="ruby-node">%w(a b)</span>.<span class="ruby-identifier">zip_with</span>(<span class="ruby-node">%w(c d)</span>, :<span class="ruby-operator">+</span>)
194
+ <span class="ruby-comment">#=&gt; [&quot;ac&quot;, &quot;bd&quot;]</span>
195
+ </pre>
196
+
197
+ <p>For more complex combinations, a block can be provided:</p>
198
+
199
+ <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">zw</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-identifier">a</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>*<span class="ruby-identifier">b</span> }
200
+ <span class="ruby-comment">#=&gt; [15, 16, 17]</span>
201
+ </pre>
202
+
203
+
204
+
205
+ <div class="method-source-code" id="zip_with-source">
206
+ <pre><span class="ruby-comment"># File lib/shenanigans/array/zip_with.rb, line 16</span>
207
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">zip_with</span>(<span class="ruby-identifier">other</span>, <span class="ruby-identifier">op</span>=<span class="ruby-keyword">nil</span>)
208
+ <span class="ruby-keyword">return</span> [] <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">empty?</span>
209
+ <span class="ruby-identifier">clipped</span> = <span class="ruby-keyword">self</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">other</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
210
+ <span class="ruby-identifier">zipped</span> = <span class="ruby-identifier">clipped</span>.<span class="ruby-identifier">zip</span>(<span class="ruby-identifier">other</span>)
211
+
212
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">op</span>
213
+ <span class="ruby-identifier">zipped</span>.<span class="ruby-identifier">map</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-identifier">a</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">op</span>, <span class="ruby-identifier">b</span>) }
214
+ <span class="ruby-keyword">else</span>
215
+ <span class="ruby-identifier">zipped</span>.<span class="ruby-identifier">map</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-keyword">yield</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>) }
216
+ <span class="ruby-keyword">end</span>
217
+ <span class="ruby-keyword">end</span></pre>
218
+ </div><!-- zip_with-source -->
219
+
220
+ </div>
221
+
222
+
223
+
224
+
225
+ </div><!-- zip_with-method -->
226
+
227
+
228
+ </section><!-- public-instance-method-details -->
229
+
230
+ </section><!-- 5Buntitled-5D -->
231
+
232
+ </div><!-- documentation -->
233
+
234
+
235
+ <footer id="validator-badges">
236
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
237
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
238
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
239
+ </footer>
240
+
data/doc/Kernel.html ADDED
@@ -0,0 +1,283 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>module Kernel - Shenanigans</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="module">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/shenanigans/kernel/fn.rb
51
+ <li>lib/shenanigans/kernel/prompt.rb
52
+ <li>lib/shenanigans/kernel/with.rb
53
+ </ul>
54
+ </nav>
55
+
56
+
57
+ </div>
58
+
59
+ <div id="class-metadata">
60
+
61
+
62
+
63
+ <!-- Method Quickref -->
64
+ <nav id="method-list-section" class="section">
65
+ <h3 class="section-header">Methods</h3>
66
+
67
+ <ul class="link-list">
68
+
69
+ <li><a href="#method-i-fn">#fn</a>
70
+
71
+ <li><a href="#method-i-prompt">#prompt</a>
72
+
73
+ <li><a href="#method-i-with">#with</a>
74
+
75
+ </ul>
76
+ </nav>
77
+
78
+ </div>
79
+
80
+ <div id="project-metadata">
81
+ <nav id="fileindex-section" class="section project-section">
82
+ <h3 class="section-header">Pages</h3>
83
+
84
+ <ul>
85
+
86
+ <li class="file"><a href="./README_rdoc.html">README</a>
87
+
88
+ </ul>
89
+ </nav>
90
+
91
+ <nav id="classindex-section" class="section project-section">
92
+ <h3 class="section-header">Class and Module Index</h3>
93
+
94
+ <ul class="link-list">
95
+
96
+ <li><a href="./Array.html">Array</a>
97
+
98
+ <li><a href="./Kernel.html">Kernel</a>
99
+
100
+ <li><a href="./Object.html">Object</a>
101
+
102
+ </ul>
103
+ </nav>
104
+
105
+ </div>
106
+ </nav>
107
+
108
+ <div id="documentation">
109
+ <h1 class="module">module Kernel</h1>
110
+
111
+ <div id="description" class="description">
112
+
113
+ </div><!-- description -->
114
+
115
+
116
+
117
+
118
+ <section id="5Buntitled-5D" class="documentation-section">
119
+
120
+
121
+
122
+
123
+
124
+ <!-- Constants -->
125
+ <section id="constants-list" class="section">
126
+ <h3 class="section-header">Constants</h3>
127
+ <dl>
128
+
129
+ <dt id="CONVERSIONS">CONVERSIONS
130
+
131
+ <dd class="description"><p>Currently only used by <code>prompt</code>: <code>:to_i</code>,
132
+ <code>:to_f</code>, <code>:to_r</code>, <code>:to_sym</code>,
133
+ <code>:to_c</code></p>
134
+
135
+
136
+ </dl>
137
+ </section>
138
+
139
+
140
+
141
+
142
+ <!-- Methods -->
143
+
144
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
145
+ <h3 class="section-header">Public Instance Methods</h3>
146
+
147
+
148
+ <div id="method-i-fn" class="method-detail ">
149
+
150
+ <div class="method-heading">
151
+ <span class="method-name">fn</span><span
152
+ class="method-args">(*funs)</span>
153
+ <span class="method-click-advice">click to toggle source</span>
154
+ </div>
155
+
156
+
157
+ <div class="method-description">
158
+
159
+ <p>Composes a list of functions. Functions can be specified as symbols or
160
+ lambdas.</p>
161
+
162
+ <pre class="ruby">[<span class="ruby-string">&quot;foo bar&quot;</span>, <span class="ruby-string">&quot;baz qux&quot;</span>].<span class="ruby-identifier">map</span> &amp;<span class="ruby-identifier">fn</span>(:<span class="ruby-identifier">split</span>, :<span class="ruby-identifier">last</span>)
163
+ <span class="ruby-comment">#=&gt; [&quot;bar&quot;, &quot;qux&quot;]</span>
164
+
165
+ (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>).<span class="ruby-identifier">map</span> &amp;<span class="ruby-identifier">fn</span>(:<span class="ruby-keyword">next</span>, <span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-identifier">x</span> { <span class="ruby-identifier">x</span> * <span class="ruby-identifier">x</span> }, <span class="ruby-operator">-</span><span class="ruby-operator">&gt;</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> } )
166
+ <span class="ruby-comment">#=&gt; [2.0, 4.5, 8.0]</span>
167
+ </pre>
168
+
169
+
170
+
171
+ <div class="method-source-code" id="fn-source">
172
+ <pre><span class="ruby-comment"># File lib/shenanigans/kernel/fn.rb, line 9</span>
173
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">fn</span>(*<span class="ruby-identifier">funs</span>)
174
+ <span class="ruby-operator">-</span><span class="ruby-operator">&gt;</span> <span class="ruby-identifier">x</span> <span class="ruby-keyword">do</span>
175
+ <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>
176
+ <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>)
177
+ <span class="ruby-keyword">end</span>
178
+ <span class="ruby-keyword">end</span>
179
+ <span class="ruby-keyword">end</span></pre>
180
+ </div><!-- fn-source -->
181
+
182
+ </div>
183
+
184
+
185
+
186
+
187
+ </div><!-- fn-method -->
188
+
189
+
190
+ <div id="method-i-prompt" class="method-detail ">
191
+
192
+ <div class="method-heading">
193
+ <span class="method-name">prompt</span><span
194
+ class="method-args">(text='', conversion=nil)</span>
195
+ <span class="method-click-advice">click to toggle source</span>
196
+ </div>
197
+
198
+
199
+ <div class="method-description">
200
+
201
+ <p>Displays a prompt and returns chomped input. Modelled after the Python
202
+ method <code>raw_input</code>, but also can be supplied with an optional
203
+ conversion method.</p>
204
+
205
+ <pre class="ruby"><span class="ruby-identifier">prompt</span>(<span class="ruby-string">&quot;Prompt&gt; &quot;</span>)
206
+ <span class="ruby-constant">Prompt</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">12</span>
207
+ <span class="ruby-comment">#=&gt; &quot;12&quot;</span>
208
+
209
+ <span class="ruby-identifier">prompt</span>(<span class="ruby-string">&quot;Prompt&gt; &quot;</span>, :<span class="ruby-identifier">to_f</span>)
210
+ <span class="ruby-constant">Prompt</span><span class="ruby-operator">&gt;</span> <span class="ruby-value">12</span>
211
+ <span class="ruby-comment">#=&gt; 12.0</span>
212
+ </pre>
213
+
214
+
215
+
216
+ <div class="method-source-code" id="prompt-source">
217
+ <pre><span class="ruby-comment"># File lib/shenanigans/kernel/prompt.rb, line 17</span>
218
+ <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>)
219
+ <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>
220
+ <span class="ruby-identifier">input</span> = <span class="ruby-identifier">gets</span>.<span class="ruby-identifier">chomp</span>
221
+ <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>
222
+ <span class="ruby-keyword">end</span></pre>
223
+ </div><!-- prompt-source -->
224
+
225
+ </div>
226
+
227
+
228
+
229
+
230
+ </div><!-- prompt-method -->
231
+
232
+
233
+ <div id="method-i-with" class="method-detail ">
234
+
235
+ <div class="method-heading">
236
+ <span class="method-name">with</span><span
237
+ class="method-args">(o, &blk)</span>
238
+ <span class="method-click-advice">click to toggle source</span>
239
+ </div>
240
+
241
+
242
+ <div class="method-description">
243
+
244
+ <p>A Pascal/ActionScript like <code>with</code> method. Yields its argument to
245
+ the provided block and then returns it.</p>
246
+
247
+ <pre class="ruby"><span class="ruby-identifier">with</span>([]) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
248
+ <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;a&quot;</span>
249
+ <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;b&quot;</span>
250
+ <span class="ruby-keyword">end</span>
251
+ <span class="ruby-comment">#=&gt; [&quot;a&quot;, &quot;b&quot;]</span>
252
+ </pre>
253
+
254
+
255
+
256
+ <div class="method-source-code" id="with-source">
257
+ <pre><span class="ruby-comment"># File lib/shenanigans/kernel/with.rb, line 9</span>
258
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">with</span>(<span class="ruby-identifier">o</span>, &amp;<span class="ruby-identifier">blk</span>)
259
+ <span class="ruby-identifier">o</span>.<span class="ruby-identifier">tap</span>(&amp;<span class="ruby-identifier">blk</span>)
260
+ <span class="ruby-keyword">end</span></pre>
261
+ </div><!-- with-source -->
262
+
263
+ </div>
264
+
265
+
266
+
267
+
268
+ </div><!-- with-method -->
269
+
270
+
271
+ </section><!-- public-instance-method-details -->
272
+
273
+ </section><!-- 5Buntitled-5D -->
274
+
275
+ </div><!-- documentation -->
276
+
277
+
278
+ <footer id="validator-badges">
279
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
280
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
281
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
282
+ </footer>
283
+