shenanigans 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -3
  3. data/README.rdoc +1 -1
  4. data/doc/Array.html +423 -202
  5. data/doc/Fixnum.html +155 -140
  6. data/doc/Hash.html +305 -206
  7. data/doc/Kernel.html +360 -249
  8. data/doc/Module.html +181 -153
  9. data/doc/Object.html +210 -201
  10. data/doc/String.html +166 -139
  11. data/doc/_index.html +188 -0
  12. data/doc/class_list.html +54 -0
  13. data/doc/css/common.css +1 -0
  14. data/doc/css/full_list.css +57 -0
  15. data/doc/css/style.css +338 -0
  16. data/doc/file.README.html +162 -0
  17. data/doc/file_list.html +56 -0
  18. data/doc/frames.html +26 -0
  19. data/doc/index.html +62 -80
  20. data/doc/js/app.js +219 -0
  21. data/doc/js/full_list.js +178 -0
  22. data/doc/js/jquery.js +4 -18
  23. data/doc/method_list.html +149 -0
  24. data/doc/top-level-namespace.html +114 -0
  25. data/lib/shenanigans.rb +3 -1
  26. data/lib/shenanigans/array.rb +3 -3
  27. data/lib/shenanigans/array/reductions.rb +29 -0
  28. data/lib/shenanigans/kernel.rb +4 -4
  29. data/lib/shenanigans/module.rb +1 -1
  30. data/lib/shenanigans/object.rb +2 -2
  31. data/lib/shenanigans/string.rb +1 -1
  32. data/test/array/test_reductions.rb +27 -0
  33. metadata +16 -36
  34. data/doc/README_rdoc.html +0 -199
  35. data/doc/created.rid +0 -25
  36. data/doc/images/add.png +0 -0
  37. data/doc/images/arrow_up.png +0 -0
  38. data/doc/images/brick.png +0 -0
  39. data/doc/images/brick_link.png +0 -0
  40. data/doc/images/bug.png +0 -0
  41. data/doc/images/bullet_black.png +0 -0
  42. data/doc/images/bullet_toggle_minus.png +0 -0
  43. data/doc/images/bullet_toggle_plus.png +0 -0
  44. data/doc/images/date.png +0 -0
  45. data/doc/images/delete.png +0 -0
  46. data/doc/images/find.png +0 -0
  47. data/doc/images/loadingAnimation.gif +0 -0
  48. data/doc/images/macFFBgHack.png +0 -0
  49. data/doc/images/package.png +0 -0
  50. data/doc/images/page_green.png +0 -0
  51. data/doc/images/page_white_text.png +0 -0
  52. data/doc/images/page_white_width.png +0 -0
  53. data/doc/images/plugin.png +0 -0
  54. data/doc/images/ruby.png +0 -0
  55. data/doc/images/tag_blue.png +0 -0
  56. data/doc/images/tag_green.png +0 -0
  57. data/doc/images/transparent.png +0 -0
  58. data/doc/images/wrench.png +0 -0
  59. data/doc/images/wrench_orange.png +0 -0
  60. data/doc/images/zoom.png +0 -0
  61. data/doc/js/darkfish.js +0 -155
  62. data/doc/js/navigation.js +0 -142
  63. data/doc/js/search.js +0 -94
  64. data/doc/js/search_index.js +0 -1
  65. data/doc/js/searcher.js +0 -228
  66. data/doc/rdoc.css +0 -595
  67. data/doc/table_of_contents.html +0 -114
@@ -0,0 +1,114 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.7.3
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Kernel.html" title="Kernel (module)">Kernel</a></span>
89
+
90
+
91
+
92
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span>, <span class='object_link'><a href="Fixnum.html" title="Fixnum (class)">Fixnum</a></span>, <span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span>, <span class='object_link'><a href="Module.html" title="Module (class)">Module</a></span>, <span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span>, <span class='object_link'><a href="String.html" title="String (class)">String</a></span>
93
+
94
+
95
+ </p>
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ </div>
106
+
107
+ <div id="footer">
108
+ Generated on Tue Dec 31 15:41:29 2013 by
109
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
+ 0.8.7.3 (ruby-2.0.0).
111
+ </div>
112
+
113
+ </body>
114
+ </html>
data/lib/shenanigans.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'shenanigans/array'
2
+ require 'shenanigans/fixnum'
2
3
  require 'shenanigans/hash'
3
4
  require 'shenanigans/kernel'
5
+ require 'shenanigans/module'
4
6
  require 'shenanigans/object'
5
- require 'shenanigans/fixnum'
7
+ require 'shenanigans/string'
@@ -1,3 +1,3 @@
1
- require_relative "array/caret"
2
- require_relative "array/random_subarray"
3
- require_relative "array/zip_with"
1
+ require_relative 'array/caret'
2
+ require_relative 'array/random_subarray'
3
+ require_relative 'array/zip_with'
@@ -0,0 +1,29 @@
1
+ class Array
2
+ # Similar to +reduce+/+inject+, but also returns intermediate values. Has the same interface as +reduce+/+inject+, so an initial value, an oprator or both can be supplied. This method may eventually be moved to the +Enumerable+ module.
3
+ #
4
+ # a = [*1..4]
5
+ # a.reductions(:+)
6
+ # #=> 10
7
+ # a.reductions(50, :+)
8
+ # #=> 60
9
+ # %w(a b c).reductions { |s1, s2| s1+s2 }
10
+ # #=> ["a", "ab", "abc"]
11
+ def reductions(*args, &block)
12
+ arr = dup
13
+
14
+ if args.size == 1
15
+ Symbol === (arg = args.first) ? op = arg : initial = arg
16
+ else
17
+ initial, op, _ = args
18
+ end
19
+
20
+ raise ArgumentError, "Need an operator or block" unless op || block
21
+
22
+ initial ||= arr.shift
23
+
24
+ arr.inject([initial, [initial]]) do |(acc, result), el|
25
+ val = op ? acc.send(op, el) : yield(acc, el)
26
+ [val, result << val]
27
+ end.last
28
+ end
29
+ end
@@ -1,4 +1,4 @@
1
- require_relative "kernel/fn"
2
- require_relative "kernel/prompt"
3
- require_relative "kernel/with"
4
- require_relative "kernel/require_optional"
1
+ require_relative 'kernel/fn'
2
+ require_relative 'kernel/prompt'
3
+ require_relative 'kernel/with'
4
+ require_relative 'kernel/require_optional'
@@ -1 +1 @@
1
- require_relative "module/private_accessor"
1
+ require_relative 'module/private_accessor'
@@ -1,2 +1,2 @@
1
- require_relative "object/it"
2
- require_relative "object/display"
1
+ require_relative 'object/it'
2
+ require_relative 'object/display'
@@ -1 +1 @@
1
- require_relative "string/in_groups_of"
1
+ require_relative 'string/in_groups_of'
@@ -0,0 +1,27 @@
1
+ require 'minitest/autorun'
2
+ require 'shenanigans/array/reductions'
3
+
4
+ class ArrayReductions < MiniTest::Unit::TestCase
5
+ TEST_ARRAY = [*1..4]
6
+
7
+ def test_reductions_without_params_or_block
8
+ assert_raises(ArgumentError) { TEST_ARRAY.reductions }
9
+ end
10
+
11
+ def test_reductions_operator_only
12
+ assert TEST_ARRAY.reductions(:+) == [1,3,6,10]
13
+ end
14
+
15
+ def test_reductions_initial_only
16
+ assert TEST_ARRAY.reductions(50) { |acc,b| acc+b} == [50,51,53,56,60]
17
+ end
18
+
19
+ def test_reductions_inital_and_operator
20
+ assert TEST_ARRAY.reductions(50, :+) == [50,51,53,56,60]
21
+ end
22
+
23
+ def test_reductions_without_params
24
+ assert TEST_ARRAY.reductions { |acc,b| acc+b} == [1,3,6,10]
25
+ assert %w(a b c).reductions { |s1, s2| s1+s2 } == %w(a ab abc)
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shenanigans
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kohl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A collection of extensions for various Ruby core classes.
14
14
  email: citizen428@gmail.com
@@ -19,49 +19,27 @@ files:
19
19
  - Gemfile
20
20
  - LICENSE
21
21
  - README.rdoc
22
+ - doc/frames.html
23
+ - doc/top-level-namespace.html
24
+ - doc/file_list.html
22
25
  - doc/Fixnum.html
23
26
  - doc/Object.html
24
27
  - doc/Hash.html
25
- - doc/images/bullet_black.png
26
- - doc/images/bullet_toggle_minus.png
27
- - doc/images/tag_blue.png
28
- - doc/images/plugin.png
29
- - doc/images/page_white_text.png
30
- - doc/images/brick.png
31
- - doc/images/page_white_width.png
32
- - doc/images/wrench_orange.png
33
- - doc/images/package.png
34
- - doc/images/date.png
35
- - doc/images/bug.png
36
- - doc/images/brick_link.png
37
- - doc/images/tag_green.png
38
- - doc/images/find.png
39
- - doc/images/page_green.png
40
- - doc/images/ruby.png
41
- - doc/images/zoom.png
42
- - doc/images/transparent.png
43
- - doc/images/delete.png
44
- - doc/images/wrench.png
45
- - doc/images/bullet_toggle_plus.png
46
- - doc/images/loadingAnimation.gif
47
- - doc/images/add.png
48
- - doc/images/arrow_up.png
49
- - doc/images/macFFBgHack.png
28
+ - doc/class_list.html
50
29
  - doc/Module.html
51
30
  - doc/index.html
52
- - doc/table_of_contents.html
53
- - doc/rdoc.css
54
31
  - doc/Array.html
32
+ - doc/css/style.css
33
+ - doc/css/common.css
34
+ - doc/css/full_list.css
55
35
  - doc/String.html
56
- - doc/created.rid
36
+ - doc/method_list.html
57
37
  - doc/Kernel.html
58
38
  - doc/js/jquery.js
59
- - doc/js/search_index.js
60
- - doc/js/searcher.js
61
- - doc/js/navigation.js
62
- - doc/js/search.js
63
- - doc/js/darkfish.js
64
- - doc/README_rdoc.html
39
+ - doc/js/app.js
40
+ - doc/js/full_list.js
41
+ - doc/_index.html
42
+ - doc/file.README.html
65
43
  - lib/shenanigans.rb
66
44
  - lib/shenanigans/fixnum/string_length.rb
67
45
  - lib/shenanigans/object.rb
@@ -75,6 +53,7 @@ files:
75
53
  - lib/shenanigans/array/zip_with.rb
76
54
  - lib/shenanigans/array/caret.rb
77
55
  - lib/shenanigans/array/random_subarray.rb
56
+ - lib/shenanigans/array/reductions.rb
78
57
  - lib/shenanigans/fixnum.rb
79
58
  - lib/shenanigans/hash/has_shape_pred.rb
80
59
  - lib/shenanigans/hash/to_ostruct.rb
@@ -92,6 +71,7 @@ files:
92
71
  - test/kernel/test_require_optional.rb
93
72
  - test/array/test_zip_with.rb
94
73
  - test/array/test_random_subarray.rb
74
+ - test/array/test_reductions.rb
95
75
  - test/array/test_caret.rb
96
76
  - test/hash/test_extract.rb
97
77
  - test/hash/test_to_ostruct.rb
data/doc/README_rdoc.html DELETED
@@ -1,199 +0,0 @@
1
- <!DOCTYPE html>
2
-
3
- <html>
4
- <head>
5
- <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
-
7
- <title>README - 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 class="file">
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
-
47
- <div id="table-of-contents">
48
- <nav class="section">
49
- <h3 class="section-header">Table of Contents</h3>
50
- <ul>
51
- <li><a href="#label-Shenanigans">Shenanigans</a>
52
- <li><a href="#label-Introduction">Introduction</a>
53
- <li><a href="#label-Installation">Installation</a>
54
- <li><a href="#label-Usage">Usage</a>
55
- <li><a href="#label-Contribute">Contribute</a>
56
- <li><a href="#label-Authors">Authors</a>
57
- <li><a href="#label-License">License</a>
58
- </ul>
59
- </nav>
60
- </div>
61
-
62
-
63
- <div id="project-metadata">
64
- <nav id="fileindex-section" class="section project-section">
65
- <h3 class="section-header">Pages</h3>
66
-
67
- <ul>
68
-
69
- <li class="file"><a href="./README_rdoc.html">README</a>
70
-
71
- </ul>
72
- </nav>
73
-
74
- <nav id="classindex-section" class="section project-section">
75
- <h3 class="section-header">Class and Module Index</h3>
76
-
77
- <ul class="link-list">
78
-
79
- <li><a href="./Array.html">Array</a>
80
-
81
- <li><a href="./Fixnum.html">Fixnum</a>
82
-
83
- <li><a href="./Hash.html">Hash</a>
84
-
85
- <li><a href="./Kernel.html">Kernel</a>
86
-
87
- <li><a href="./Module.html">Module</a>
88
-
89
- <li><a href="./Object.html">Object</a>
90
-
91
- <li><a href="./String.html">String</a>
92
-
93
- </ul>
94
- </nav>
95
-
96
- </div>
97
- </nav>
98
-
99
- <div id="documentation" class="description">
100
-
101
- <h1 id="label-Shenanigans">Shenanigans<span><a href="#label-Shenanigans">&para;</a> <a href="#documentation">&uarr;</a></span></h1>
102
-
103
- <p><strong>shenanigan</strong> (plural shenanigans):</p>
104
- <ol><li>
105
- <p>Trickery, games; skulduggery. To “call”, “claim” or “declare” shenanigans
106
- is to rhetorically label something as officially deceitful, improper, or
107
- otherwise incorrect. <em>“The advertisement said it would cost $50 but they
108
- charged me $75 at the register. I declare shenanigans.”</em> The speaker
109
- passes off the statement as having some sort of implied official effect,
110
- but in reality, it is simply a complaint.</p>
111
- </li><li>
112
- <p>A deceitful confidence trick, or mischief causing discomfort or annoyance.
113
- <em>You should learn to spot their shenanigans and avoid being fooled.</em></p>
114
- </li><li>
115
- <p>Mischievous play, especially by children.</p>
116
- </li></ol>
117
-
118
- <p>Source: <a
119
- href="http://en.wiktionary.org/wiki/shenanigan#English">Wiktionary</a></p>
120
-
121
- <h2 id="label-Introduction">Introduction<span><a href="#label-Introduction">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
122
-
123
- <p>Ruby Facets is the premiere collection of general purpose method extensions
124
- and standard additions for the Ruby programming language. This is not Ruby
125
- Facets though, so what you get is a random collection of methods I wrote
126
- because I found them interesting and/or useful. Some of them I actually
127
- also contributed to Facets, although sometimes they have different names or
128
- slightly different implementations.</p>
129
-
130
- <h2 id="label-Installation">Installation<span><a href="#label-Installation">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
131
-
132
- <p>Shenanigans can be installed via <a
133
- href="http://rubygems.org/">RubyGems</a>.</p>
134
-
135
- <pre>$ gem install shenanigans</pre>
136
-
137
- <p>I only works on 1.9.3 and I generally only test it with the most current
138
- Ruby release.</p>
139
-
140
- <h2 id="label-Usage">Usage<span><a href="#label-Usage">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
141
-
142
- <p>If you really want the whole shebang, you can get it this way:</p>
143
-
144
- <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;shenanigans&#39;</span>
145
- </pre>
146
-
147
- <p>Requiring a single method works as follows:</p>
148
-
149
- <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;shenanigans/&lt;class|module&gt;/&lt;method&gt;&#39;</span>
150
- </pre>
151
-
152
- <p>Requiring all the extensions of a class or module also works:</p>
153
-
154
- <pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;shenanigans/kernel&#39;</span>
155
- </pre>
156
-
157
- <h2 id="label-Contribute">Contribute<span><a href="#label-Contribute">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
158
-
159
- <p>If you have something you want to contribute to Shenanigans, you shoud
160
- reconsider and add it to Facets instead. This is a library for my own wonky
161
- ideas and I don&#39;t think it will ever see any real usage.</p>
162
-
163
- <h2 id="label-Authors">Authors<span><a href="#label-Authors">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
164
-
165
- <p>This project was created by Michael Kohl. He can be reached via email at
166
- citizen428 at gmail.com.</p>
167
-
168
- <h2 id="label-License">License<span><a href="#label-License">&para;</a> <a href="#documentation">&uarr;</a></span></h2>
169
-
170
- <p>Copyright © 2012 Michael Kohl</p>
171
-
172
- <p>Permission is hereby granted, free of charge, to any person obtaining a
173
- copy of this software and associated documentation files (the “Software”),
174
- to deal in the Software without restriction, including without limitation
175
- the rights to use, copy, modify, merge, publish, distribute, sublicense,
176
- and/or sell copies of the Software, and to permit persons to whom the
177
- Software is furnished to do so, subject to the following conditions:</p>
178
-
179
- <p>The above copyright notice and this permission notice shall be included in
180
- all copies or substantial portions of the Software.</p>
181
-
182
- <p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
183
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
185
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
186
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
187
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
188
- DEALINGS IN THE SOFTWARE.</p>
189
-
190
- </div>
191
-
192
-
193
-
194
- <footer id="validator-badges">
195
- <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
196
- <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
197
- <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
198
- </footer>
199
-