shenanigans 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/Array.html +37 -0
- data/doc/Hash.html +22 -24
- data/doc/created.rid +4 -3
- data/doc/js/search_index.js +1 -1
- data/doc/table_of_contents.html +2 -0
- data/lib/shenanigans/array.rb +1 -0
- data/lib/shenanigans/array/caret.rb +8 -0
- data/lib/shenanigans/hash/to_ostruct.rb +19 -20
- data/lib/shenanigans/object.rb +1 -1
- data/lib/shenanigans/object/{identity.rb → it.rb} +2 -2
- data/test/array/test_caret.rb +9 -0
- data/test/object/test_it.rb +10 -0
- metadata +6 -4
- data/test/object/test_identity.rb +0 -9
data/doc/Array.html
CHANGED
@@ -47,6 +47,7 @@
|
|
47
47
|
<nav id="file-list-section" class="section">
|
48
48
|
<h3 class="section-header">Defined In</h3>
|
49
49
|
<ul>
|
50
|
+
<li>lib/shenanigans/array/caret.rb
|
50
51
|
<li>lib/shenanigans/array/random_subarray.rb
|
51
52
|
<li>lib/shenanigans/array/zip_with.rb
|
52
53
|
</ul>
|
@@ -71,6 +72,8 @@
|
|
71
72
|
|
72
73
|
<ul class="link-list">
|
73
74
|
|
75
|
+
<li><a href="#method-i-5E">#^</a>
|
76
|
+
|
74
77
|
<li><a href="#method-i-random_subarray">#random_subarray</a>
|
75
78
|
|
76
79
|
<li><a href="#method-i-zip_with">#zip_with</a>
|
@@ -135,6 +138,40 @@
|
|
135
138
|
<h3 class="section-header">Public Instance Methods</h3>
|
136
139
|
|
137
140
|
|
141
|
+
<div id="method-i-5E" class="method-detail ">
|
142
|
+
|
143
|
+
<div class="method-heading">
|
144
|
+
<span class="method-name">^</span><span
|
145
|
+
class="method-args">(other)</span>
|
146
|
+
<span class="method-click-advice">click to toggle source</span>
|
147
|
+
</div>
|
148
|
+
|
149
|
+
|
150
|
+
<div class="method-description">
|
151
|
+
|
152
|
+
<p>Returns an array containing elements exclusive between two arrays.</p>
|
153
|
+
|
154
|
+
<pre class="ruby">[<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>] <span class="ruby-operator">^</span> [<span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">4</span>]
|
155
|
+
<span class="ruby-comment">#=> [3, 4]</span>
|
156
|
+
</pre>
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
<div class="method-source-code" id="5E-source">
|
161
|
+
<pre><span class="ruby-comment"># File lib/shenanigans/array/caret.rb, line 5</span>
|
162
|
+
<span class="ruby-keyword">def</span> <span class="ruby-operator">^</span>(<span class="ruby-identifier">other</span>)
|
163
|
+
(<span class="ruby-keyword">self</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">other</span>) <span class="ruby-operator">-</span> (<span class="ruby-keyword">self</span> & <span class="ruby-identifier">other</span>)
|
164
|
+
<span class="ruby-keyword">end</span></pre>
|
165
|
+
</div><!-- 5E-source -->
|
166
|
+
|
167
|
+
</div>
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
</div><!-- 5E-method -->
|
173
|
+
|
174
|
+
|
138
175
|
<div id="method-i-random_subarray" class="method-detail ">
|
139
176
|
|
140
177
|
<div class="method-heading">
|
data/doc/Hash.html
CHANGED
@@ -115,27 +115,6 @@
|
|
115
115
|
|
116
116
|
<div id="description" class="description">
|
117
117
|
|
118
|
-
<p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es
|
119
|
-
to <code>OpenStruct</code>s. Especially useful for parsing YAML.</p>
|
120
|
-
|
121
|
-
<pre class="ruby"><span class="ruby-identifier">yaml</span>=<span class="ruby-string">"subject: Programming Languages
|
122
|
-
languages:
|
123
|
-
- name : Ruby
|
124
|
-
creator : Matz
|
125
|
-
- name : Python
|
126
|
-
creator : Guido van Rossum
|
127
|
-
- name : Perl
|
128
|
-
creator : Larry Wall
|
129
|
-
"</span>
|
130
|
-
<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>
|
131
|
-
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">subject</span>
|
132
|
-
<span class="ruby-comment">#=> "Programming Languages"</span>
|
133
|
-
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">languages</span>.<span class="ruby-identifier">first</span>
|
134
|
-
<span class="ruby-comment">#=> #<OpenStruct name="Ruby", creator="Matz"></span>
|
135
|
-
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">languages</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">creator</span>
|
136
|
-
<span class="ruby-comment">#=> "Matz"</span>
|
137
|
-
</pre>
|
138
|
-
|
139
118
|
</div><!-- description -->
|
140
119
|
|
141
120
|
|
@@ -214,17 +193,36 @@ languages:
|
|
214
193
|
|
215
194
|
<div class="method-description">
|
216
195
|
|
217
|
-
|
196
|
+
<p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es
|
197
|
+
to <code>OpenStruct</code>s. Especially useful for parsing YAML.</p>
|
198
|
+
|
199
|
+
<pre class="ruby"><span class="ruby-identifier">yaml</span>=<span class="ruby-string">"subject: Programming Languages
|
200
|
+
languages:
|
201
|
+
- name : Ruby
|
202
|
+
creator : Matz
|
203
|
+
- name : Python
|
204
|
+
creator : Guido van Rossum
|
205
|
+
- name : Perl
|
206
|
+
creator : Larry Wall
|
207
|
+
"</span>
|
208
|
+
<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>
|
209
|
+
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">subject</span>
|
210
|
+
<span class="ruby-comment">#=> "Programming Languages"</span>
|
211
|
+
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">languages</span>.<span class="ruby-identifier">first</span>
|
212
|
+
<span class="ruby-comment">#=> #<OpenStruct name="Ruby", creator="Matz"></span>
|
213
|
+
<span class="ruby-identifier">struct</span>.<span class="ruby-identifier">languages</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">creator</span>
|
214
|
+
<span class="ruby-comment">#=> "Matz"</span>
|
215
|
+
</pre>
|
218
216
|
|
219
217
|
|
220
218
|
|
221
219
|
<div class="method-source-code" id="to_ostruct-source">
|
222
|
-
<pre><span class="ruby-comment"># File lib/shenanigans/hash/to_ostruct.rb, line
|
220
|
+
<pre><span class="ruby-comment"># File lib/shenanigans/hash/to_ostruct.rb, line 23</span>
|
223
221
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">to_ostruct</span>
|
224
222
|
<span class="ruby-identifier">arr</span> = <span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
225
223
|
<span class="ruby-keyword">case</span> <span class="ruby-identifier">v</span>
|
226
224
|
<span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>
|
227
|
-
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">
|
225
|
+
[<span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_ostruct</span>]
|
228
226
|
<span class="ruby-keyword">when</span> <span class="ruby-constant">Array</span>
|
229
227
|
[<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-constant">Hash</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">to_ostruct</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">el</span> }]
|
230
228
|
<span class="ruby-keyword">else</span>
|
data/doc/created.rid
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
Thu,
|
1
|
+
Thu, 28 Jun 2012 09:01:37 +0200
|
2
2
|
README.rdoc Thu, 17 May 2012 11:45:08 +0200
|
3
|
+
lib/shenanigans/array/caret.rb Thu, 28 Jun 2012 09:01:33 +0200
|
3
4
|
lib/shenanigans/array/random_subarray.rb Thu, 17 May 2012 00:03:23 +0200
|
4
5
|
lib/shenanigans/array/zip_with.rb Tue, 19 Jun 2012 21:23:27 +0200
|
5
|
-
lib/shenanigans/array.rb
|
6
|
+
lib/shenanigans/array.rb Thu, 28 Jun 2012 09:00:29 +0200
|
6
7
|
lib/shenanigans/hash/has_shape_pred.rb Tue, 19 Jun 2012 21:25:03 +0200
|
7
|
-
lib/shenanigans/hash/to_ostruct.rb
|
8
|
+
lib/shenanigans/hash/to_ostruct.rb Tue, 26 Jun 2012 21:24:42 +0200
|
8
9
|
lib/shenanigans/hash.rb Thu, 21 Jun 2012 19:13:44 +0200
|
9
10
|
lib/shenanigans/kernel/fn.rb Wed, 16 May 2012 23:57:36 +0200
|
10
11
|
lib/shenanigans/kernel/prompt.rb Thu, 17 May 2012 00:10:42 +0200
|
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["array","hash","kernel","object","d()","display()","fn()","has_shape?()","identity()","prompt()","random_subarray()","to_ostruct()","with()","zip_with()","readme"],"longSearchIndex":["array","hash","kernel","object","object#d()","object#display()","kernel#fn()","hash#has_shape?()","object#identity()","kernel#prompt()","array#random_subarray()","hash#to_ostruct()","kernel#with()","array#zip_with()",""],"info":[["Array","","Array.html","",""],["Hash","","Hash.html","","
|
1
|
+
var search_data = {"index":{"searchIndex":["array","hash","kernel","object","^()","d()","display()","fn()","has_shape?()","identity()","prompt()","random_subarray()","to_ostruct()","with()","zip_with()","readme"],"longSearchIndex":["array","hash","kernel","object","array#^()","object#d()","object#display()","kernel#fn()","hash#has_shape?()","object#identity()","kernel#prompt()","array#random_subarray()","hash#to_ostruct()","kernel#with()","array#zip_with()",""],"info":[["Array","","Array.html","",""],["Hash","","Hash.html","",""],["Kernel","","Kernel.html","",""],["Object","","Object.html","",""],["^","Array","Array.html#method-i-5E","(other)","<p>Returns an array containing elements exclusive between two arrays.\n\n<pre class=\"ruby\">[<span class=\"ruby-value\">1</span>, <span class=\"ruby-value\">2</span>, <span class=\"ruby-value\">3</span>] <span class=\"ruby-operator\">^</span> [<span class=\"ruby-value\">1</span>, <span class=\"ruby-value\">2</span>, <span class=\"ruby-value\">4</span>]\n<span class=\"ruby-comment\">#=> [3, 4]</span>\n</pre>\n"],["d","Object","Object.html#method-i-d","(new_line = true)",""],["display","Object","Object.html#method-i-display","(new_line = true)","<p>Outputs the object and also returns it. Will use <code>puts</code> if\n<code>new_line</code> is <code>true</code> and <code>print</code>\notherwise.\n\n<pre>"foo".display ...</pre>\n"],["fn","Kernel","Kernel.html#method-i-fn","(*funs)","<p>Composes a list of functions. Functions can be specified as symbols or\nlambdas.\n\n<pre>["foo bar", "baz qux"].map ...</pre>\n"],["has_shape?","Hash","Hash.html#method-i-has_shape-3F","(shape)","<p>Checks if a hash has a certain structure.\n\n<pre>h = { k1: 1, k2: "1" }\nh.has_shape?(k1: Fixnum, k2: String) ...</pre>\n"],["identity","Object","Object.html#method-i-identity","()","<p>An identity method that provides access to an object’s <code>self</code>.\n\n<pre>[1,2,3,4,5,1,2,2,3].group_by(&:identity) ...</pre>\n"],["prompt","Kernel","Kernel.html#method-i-prompt","(text='', conversion=nil)","<p>Displays a prompt and returns chomped input. Modelled after the Python\nmethod <code>raw_input</code>, but also can …\n"],["random_subarray","Array","Array.html#method-i-random_subarray","(n=1)","<p>Generates random subarrays. Uses random numbers and bit-fiddling to assure\nperformant uniform distributions …\n"],["to_ostruct","Hash","Hash.html#method-i-to_ostruct","()","<p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es\nto <code>OpenStruct</code>s. Especially useful for parsing YAML …\n"],["with","Kernel","Kernel.html#method-i-with","(o, &blk)","<p>A Pascal/ActionScript like <code>with</code> method. Yields its argument to\nthe provided block and then returns it. …\n"],["zip_with","Array","Array.html#method-i-zip_with","(other, op=nil)","<p>Zip <code>self</code> with <code>other</code>, combining the elements with\nthe provided block or symbol. The resulting array will …\n"],["README","","README_rdoc.html","","<p>Shenanigans\n<p><strong>shenanigan</strong> (plural shenanigans):\n<p>Trickery, games; skulduggery. To “call”, “claim” …\n"]]}}
|
data/doc/table_of_contents.html
CHANGED
@@ -62,6 +62,8 @@
|
|
62
62
|
<h2 id="methods">Methods</h2>
|
63
63
|
<ul>
|
64
64
|
|
65
|
+
<li class="method"><a href="Array.html#method-i-5E">#^ — Array</a>
|
66
|
+
|
65
67
|
<li class="method"><a href="Object.html#method-i-d">#d — Object</a>
|
66
68
|
|
67
69
|
<li class="method"><a href="Object.html#method-i-display">#display — Object</a>
|
data/lib/shenanigans/array.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
|
-
# Recursively converts a <tt>Hash</tt> and all nested <tt>Hash</tt>es to
|
4
|
-
# <tt>OpenStruct</tt>s. Especially useful for parsing YAML.
|
5
|
-
# yaml=<<EOY
|
6
|
-
# subject: Programming Languages
|
7
|
-
# languages:
|
8
|
-
# - name : Ruby
|
9
|
-
# creator : Matz
|
10
|
-
# - name : Python
|
11
|
-
# creator : Guido van Rossum
|
12
|
-
# - name : Perl
|
13
|
-
# creator : Larry Wall
|
14
|
-
# EOY
|
15
|
-
# struct = YAML.load(yaml).to_ostruct
|
16
|
-
# struct.subject
|
17
|
-
# #=> "Programming Languages"
|
18
|
-
# struct.languages.first
|
19
|
-
# #=> #<OpenStruct name="Ruby", creator="Matz">
|
20
|
-
# struct.languages.first.creator
|
21
|
-
# #=> "Matz"
|
22
|
-
|
23
3
|
class Hash
|
4
|
+
# Recursively converts a <tt>Hash</tt> and all nested <tt>Hash</tt>es to
|
5
|
+
# <tt>OpenStruct</tt>s. Especially useful for parsing YAML.
|
6
|
+
# yaml=<<EOY
|
7
|
+
# subject: Programming Languages
|
8
|
+
# languages:
|
9
|
+
# - name : Ruby
|
10
|
+
# creator : Matz
|
11
|
+
# - name : Python
|
12
|
+
# creator : Guido van Rossum
|
13
|
+
# - name : Perl
|
14
|
+
# creator : Larry Wall
|
15
|
+
# EOY
|
16
|
+
# struct = YAML.load(yaml).to_ostruct
|
17
|
+
# struct.subject
|
18
|
+
# #=> "Programming Languages"
|
19
|
+
# struct.languages.first
|
20
|
+
# #=> #<OpenStruct name="Ruby", creator="Matz">
|
21
|
+
# struct.languages.first.creator
|
22
|
+
# #=> "Matz"
|
24
23
|
def to_ostruct
|
25
24
|
arr = map do |k, v|
|
26
25
|
case v
|
data/lib/shenanigans/object.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require_relative "object/
|
1
|
+
require_relative "object/it"
|
2
2
|
require_relative "object/display"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
class Object
|
2
2
|
# An identity method that provides access to an object's
|
3
3
|
# <tt>self</tt>.
|
4
|
-
# [1,2,3,4,5,1,2,2,3].group_by(&:
|
4
|
+
# [1,2,3,4,5,1,2,2,3].group_by(&:it)
|
5
5
|
# #=> {1=>[1, 1], 2=>[2, 2, 2], 3=>[3, 3], 4=>[4], 5=>[5]}
|
6
|
-
def
|
6
|
+
def it
|
7
7
|
self
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'shenanigans/object/it'
|
3
|
+
|
4
|
+
class Identity < MiniTest::Unit::TestCase
|
5
|
+
def test_identity
|
6
|
+
arr = [1, "2", :tree]
|
7
|
+
assert arr.map(&:it) == arr
|
8
|
+
assert [1,1,2,3].group_by(&:it) == {1 => [1, 1], 2 => [2], 3 => [3]}
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shenanigans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: citizen428@gmail.com
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- doc/rdoc.css
|
60
60
|
- doc/README_rdoc.html
|
61
61
|
- doc/table_of_contents.html
|
62
|
+
- lib/shenanigans/array/caret.rb
|
62
63
|
- lib/shenanigans/array/random_subarray.rb
|
63
64
|
- lib/shenanigans/array/zip_with.rb
|
64
65
|
- lib/shenanigans/array.rb
|
@@ -70,11 +71,12 @@ files:
|
|
70
71
|
- lib/shenanigans/kernel/with.rb
|
71
72
|
- lib/shenanigans/kernel.rb
|
72
73
|
- lib/shenanigans/object/display.rb
|
73
|
-
- lib/shenanigans/object/
|
74
|
+
- lib/shenanigans/object/it.rb
|
74
75
|
- lib/shenanigans/object.rb
|
75
76
|
- lib/shenanigans/README.mdown
|
76
77
|
- lib/shenanigans/shenanigans-0.0.1.gem
|
77
78
|
- lib/shenanigans.rb
|
79
|
+
- test/array/test_caret.rb
|
78
80
|
- test/array/test_random_subarray.rb
|
79
81
|
- test/array/test_zip_with.rb
|
80
82
|
- test/hash/test_has_shape_pred.rb
|
@@ -83,7 +85,7 @@ files:
|
|
83
85
|
- test/kernel/test_prompt.rb
|
84
86
|
- test/kernel/test_with.rb
|
85
87
|
- test/object/test_display.rb
|
86
|
-
- test/object/
|
88
|
+
- test/object/test_it.rb
|
87
89
|
homepage: https://github.com/citizen428/shenanigans
|
88
90
|
licenses: []
|
89
91
|
post_install_message:
|