mack_ruby_core_extensions 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -0
- data/doc/classes/Array.html +465 -0
- data/doc/classes/Class.html +181 -0
- data/doc/classes/Dir.html +190 -0
- data/doc/classes/Float.html +148 -0
- data/doc/classes/Hash.html +232 -0
- data/doc/classes/Kernel.html +182 -0
- data/doc/classes/Mack.html +111 -0
- data/doc/classes/Mack/Utils.html +111 -0
- data/doc/classes/Mack/Utils/Inflector.html +422 -0
- data/doc/classes/Math.html +188 -0
- data/doc/classes/MethodNotImplemented.html +155 -0
- data/doc/classes/Module.html +203 -0
- data/doc/classes/NilClass.html +151 -0
- data/doc/classes/Object.html +315 -0
- data/doc/classes/String.html +890 -0
- data/doc/classes/Symbol.html +148 -0
- data/doc/created.rid +1 -0
- data/doc/files/README.html +111 -0
- data/doc/files/lib/extensions/array_rb.html +101 -0
- data/doc/files/lib/extensions/class_rb.html +101 -0
- data/doc/files/lib/extensions/dir_rb.html +101 -0
- data/doc/files/lib/extensions/float_rb.html +101 -0
- data/doc/files/lib/extensions/hash_rb.html +101 -0
- data/doc/files/lib/extensions/kernel_rb.html +109 -0
- data/doc/files/lib/extensions/logger_rb.html +101 -0
- data/doc/files/lib/extensions/math_rb.html +101 -0
- data/doc/files/lib/extensions/method_not_implemented_rb.html +108 -0
- data/doc/files/lib/extensions/module_rb.html +101 -0
- data/doc/files/lib/extensions/nil_rb.html +101 -0
- data/doc/files/lib/extensions/object_rb.html +101 -0
- data/doc/files/lib/extensions/string_rb.html +108 -0
- data/doc/files/lib/extensions/symbol_rb.html +101 -0
- data/doc/files/lib/mack_ruby_core_extensions_rb.html +101 -0
- data/doc/files/lib/utils/inflections_rb.html +101 -0
- data/doc/files/lib/utils/inflector_rb.html +108 -0
- data/doc/fr_class_index.html +42 -0
- data/doc/fr_file_index.html +44 -0
- data/doc/fr_method_index.html +92 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/extensions/array.rb +101 -0
- data/lib/extensions/class.rb +19 -0
- data/lib/extensions/dir.rb +25 -0
- data/lib/extensions/float.rb +5 -0
- data/lib/extensions/hash.rb +47 -0
- data/lib/extensions/kernel.rb +30 -0
- data/lib/extensions/logger.rb +0 -0
- data/lib/extensions/math.rb +15 -0
- data/lib/extensions/method_not_implemented.rb +12 -0
- data/lib/extensions/module.rb +29 -0
- data/lib/extensions/nil.rb +8 -0
- data/lib/extensions/object.rb +103 -0
- data/lib/extensions/string.rb +261 -0
- data/lib/extensions/symbol.rb +7 -0
- data/lib/mack_ruby_core_extensions.rb +7 -0
- data/lib/utils/inflections.rb +62 -0
- data/lib/utils/inflector.rb +129 -0
- data/test/extensions/array_test.rb +15 -0
- data/test/extensions/class_test.rb +28 -0
- data/test/extensions/dir_test.rb +15 -0
- data/test/extensions/float_test.rb +15 -0
- data/test/extensions/hash_test.rb +34 -0
- data/test/extensions/kernel_test.rb +15 -0
- data/test/extensions/logger_test.rb +15 -0
- data/test/extensions/math_test.rb +15 -0
- data/test/extensions/method_not_implemented_test.rb +15 -0
- data/test/extensions/module_test.rb +57 -0
- data/test/extensions/nil_test.rb +15 -0
- data/test/extensions/object_test.rb +15 -0
- data/test/extensions/string_test.rb +104 -0
- data/test/extensions/symbol_test.rb +15 -0
- data/test/test_helper.rb +6 -0
- data/test/utils/inflection_test.rb +32 -0
- metadata +133 -0
data/README
ADDED
@@ -0,0 +1,465 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Array</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Array</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/extensions/array_rb.html">
|
59
|
+
lib/extensions/array.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
<a href="Object.html">
|
69
|
+
Object
|
70
|
+
</a>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<div id="method-list">
|
88
|
+
<h3 class="section-bar">Methods</h3>
|
89
|
+
|
90
|
+
<div class="name-list">
|
91
|
+
<a href="#M000016">count</a>
|
92
|
+
<a href="#M000008">delete_from_array</a>
|
93
|
+
<a href="#M000009">delete_from_array!</a>
|
94
|
+
<a href="#M000017">invert</a>
|
95
|
+
<a href="#M000007">parse_splat_args</a>
|
96
|
+
<a href="#M000012">pick_random</a>
|
97
|
+
<a href="#M000013">random_each</a>
|
98
|
+
<a href="#M000010">randomize</a>
|
99
|
+
<a href="#M000011">randomize!</a>
|
100
|
+
<a href="#M000014">subset?</a>
|
101
|
+
<a href="#M000015">superset?</a>
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
|
108
|
+
<!-- if includes -->
|
109
|
+
|
110
|
+
<div id="section">
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<!-- if method_list -->
|
120
|
+
<div id="methods">
|
121
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
122
|
+
|
123
|
+
<div id="method-M000016" class="method-detail">
|
124
|
+
<a name="M000016"></a>
|
125
|
+
|
126
|
+
<div class="method-heading">
|
127
|
+
<a href="#M000016" class="method-signature">
|
128
|
+
<span class="method-name">count</span><span class="method-args">()</span>
|
129
|
+
</a>
|
130
|
+
</div>
|
131
|
+
|
132
|
+
<div class="method-description">
|
133
|
+
<p>
|
134
|
+
This will give you a <a href="Array.html#M000016">count</a>, as a <a
|
135
|
+
href="Hash.html">Hash</a>, of all the values in the <a
|
136
|
+
href="Array.html">Array</a>. %w{spam spam eggs ham eggs spam}.<a
|
137
|
+
href="Array.html#M000016">count</a> # => {"eggs"=>2,
|
138
|
+
"ham"=>1, "spam"=>3}
|
139
|
+
</p>
|
140
|
+
<p><a class="source-toggle" href="#"
|
141
|
+
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
142
|
+
<div class="method-source-code" id="M000016-source">
|
143
|
+
<pre>
|
144
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 87</span>
|
145
|
+
87: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count</span>
|
146
|
+
88: <span class="ruby-identifier">k</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>)
|
147
|
+
89: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">k</span>[<span class="ruby-identifier">x</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>}
|
148
|
+
90: <span class="ruby-identifier">k</span>
|
149
|
+
91: <span class="ruby-keyword kw">end</span>
|
150
|
+
</pre>
|
151
|
+
</div>
|
152
|
+
</div>
|
153
|
+
</div>
|
154
|
+
|
155
|
+
<div id="method-M000008" class="method-detail">
|
156
|
+
<a name="M000008"></a>
|
157
|
+
|
158
|
+
<div class="method-heading">
|
159
|
+
<a href="#M000008" class="method-signature">
|
160
|
+
<span class="method-name">delete_from_array</span><span class="method-args">(args)</span>
|
161
|
+
</a>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<div class="method-description">
|
165
|
+
<p>
|
166
|
+
This allows you to delete an array of values from another array.
|
167
|
+
[1,2,3,4,5].<a href="Array.html#M000008">delete_from_array</a>([2,3,5]) #
|
168
|
+
=> [1,4]
|
169
|
+
</p>
|
170
|
+
<p><a class="source-toggle" href="#"
|
171
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
172
|
+
<div class="method-source-code" id="M000008-source">
|
173
|
+
<pre>
|
174
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 37</span>
|
175
|
+
37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_from_array</span>(<span class="ruby-identifier">args</span>)
|
176
|
+
38: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">collect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">x</span>)}.<span class="ruby-identifier">compact</span>
|
177
|
+
39: <span class="ruby-keyword kw">end</span>
|
178
|
+
</pre>
|
179
|
+
</div>
|
180
|
+
</div>
|
181
|
+
</div>
|
182
|
+
|
183
|
+
<div id="method-M000009" class="method-detail">
|
184
|
+
<a name="M000009"></a>
|
185
|
+
|
186
|
+
<div class="method-heading">
|
187
|
+
<a href="#M000009" class="method-signature">
|
188
|
+
<span class="method-name">delete_from_array!</span><span class="method-args">(args)</span>
|
189
|
+
</a>
|
190
|
+
</div>
|
191
|
+
|
192
|
+
<div class="method-description">
|
193
|
+
<p>
|
194
|
+
This calls the <a href="Array.html#M000008">delete_from_array</a> method,
|
195
|
+
but will permantly replace the existing array.
|
196
|
+
</p>
|
197
|
+
<p><a class="source-toggle" href="#"
|
198
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
199
|
+
<div class="method-source-code" id="M000009-source">
|
200
|
+
<pre>
|
201
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 42</span>
|
202
|
+
42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_from_array!</span>(<span class="ruby-identifier">args</span>)
|
203
|
+
43: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-identifier">delete_from_array</span>(<span class="ruby-identifier">args</span>))
|
204
|
+
44: <span class="ruby-keyword kw">end</span>
|
205
|
+
</pre>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
<div id="method-M000017" class="method-detail">
|
211
|
+
<a name="M000017"></a>
|
212
|
+
|
213
|
+
<div class="method-heading">
|
214
|
+
<a href="#M000017" class="method-signature">
|
215
|
+
<span class="method-name">invert</span><span class="method-args">()</span>
|
216
|
+
</a>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
<div class="method-description">
|
220
|
+
<p>
|
221
|
+
This will <a href="Array.html#M000017">invert</a> the index and the values
|
222
|
+
and return a <a href="Hash.html">Hash</a> of the results. %w{red yellow
|
223
|
+
orange}.<a href="Array.html#M000017">invert</a> # =>
|
224
|
+
{"red"=>0, "orange"=>2, "yellow"=>1}
|
225
|
+
</p>
|
226
|
+
<p><a class="source-toggle" href="#"
|
227
|
+
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
228
|
+
<div class="method-source-code" id="M000017-source">
|
229
|
+
<pre>
|
230
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 95</span>
|
231
|
+
95: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">invert</span>
|
232
|
+
96: <span class="ruby-identifier">h</span> = {}
|
233
|
+
97: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each_with_index</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">h</span>[<span class="ruby-identifier">x</span>] = <span class="ruby-identifier">i</span>}
|
234
|
+
98: <span class="ruby-identifier">h</span>
|
235
|
+
99: <span class="ruby-keyword kw">end</span>
|
236
|
+
</pre>
|
237
|
+
</div>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
<div id="method-M000007" class="method-detail">
|
242
|
+
<a name="M000007"></a>
|
243
|
+
|
244
|
+
<div class="method-heading">
|
245
|
+
<a href="#M000007" class="method-signature">
|
246
|
+
<span class="method-name">parse_splat_args</span><span class="method-args">()</span>
|
247
|
+
</a>
|
248
|
+
</div>
|
249
|
+
|
250
|
+
<div class="method-description">
|
251
|
+
<p>
|
252
|
+
This method is useful when you have a method that looks like this: def
|
253
|
+
foo(*args)
|
254
|
+
</p>
|
255
|
+
<pre>
|
256
|
+
do something
|
257
|
+
</pre>
|
258
|
+
<p>
|
259
|
+
end The problem is when you use the * like that everything that comes in is
|
260
|
+
an array. Here are a few problems with this: foo([1,2,3]) When you pass an
|
261
|
+
array into this type of method you get the following nested array:
|
262
|
+
[[1,2,3]] The <a href="Array.html#M000007">parse_splat_args</a> method, if
|
263
|
+
called, would do this: args.parse_splat_args # => [1,2,3] Now say you
|
264
|
+
called this method like such: foo(1) args would be [1]
|
265
|
+
args.parse_splat_args # => 1 Finally foo args.parse_splat_args # =>
|
266
|
+
nil
|
267
|
+
</p>
|
268
|
+
<p><a class="source-toggle" href="#"
|
269
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
270
|
+
<div class="method-source-code" id="M000007-source">
|
271
|
+
<pre>
|
272
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 21</span>
|
273
|
+
21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_splat_args</span>
|
274
|
+
22: <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">empty?</span>
|
275
|
+
23: <span class="ruby-identifier">args</span> = <span class="ruby-keyword kw">self</span><span class="ruby-comment cmt">#.flatten</span>
|
276
|
+
24: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span>
|
277
|
+
25: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
|
278
|
+
26: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span> <span class="ruby-comment cmt"># if there was only one arg passed, return just that, without the array</span>
|
279
|
+
27: <span class="ruby-keyword kw">when</span> <span class="ruby-value">0</span>
|
280
|
+
28: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># if no args were passed return nil</span>
|
281
|
+
29: <span class="ruby-keyword kw">else</span>
|
282
|
+
30: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">args</span> <span class="ruby-comment cmt"># else return the array back, cause chances are that's what they passed you!</span>
|
283
|
+
31: <span class="ruby-keyword kw">end</span>
|
284
|
+
32: <span class="ruby-keyword kw">end</span>
|
285
|
+
33: <span class="ruby-keyword kw">end</span>
|
286
|
+
</pre>
|
287
|
+
</div>
|
288
|
+
</div>
|
289
|
+
</div>
|
290
|
+
|
291
|
+
<div id="method-M000012" class="method-detail">
|
292
|
+
<a name="M000012"></a>
|
293
|
+
|
294
|
+
<div class="method-heading">
|
295
|
+
<a href="#M000012" class="method-signature">
|
296
|
+
<span class="method-name">pick_random</span><span class="method-args">()</span>
|
297
|
+
</a>
|
298
|
+
</div>
|
299
|
+
|
300
|
+
<div class="method-description">
|
301
|
+
<p>
|
302
|
+
This will pick a random value from the array
|
303
|
+
</p>
|
304
|
+
<p><a class="source-toggle" href="#"
|
305
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
306
|
+
<div class="method-source-code" id="M000012-source">
|
307
|
+
<pre>
|
308
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 65</span>
|
309
|
+
65: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pick_random</span>
|
310
|
+
66: <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">rand</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">length</span>)]
|
311
|
+
67: <span class="ruby-keyword kw">end</span>
|
312
|
+
</pre>
|
313
|
+
</div>
|
314
|
+
</div>
|
315
|
+
</div>
|
316
|
+
|
317
|
+
<div id="method-M000013" class="method-detail">
|
318
|
+
<a name="M000013"></a>
|
319
|
+
|
320
|
+
<div class="method-heading">
|
321
|
+
<a href="#M000013" class="method-signature">
|
322
|
+
<span class="method-name">random_each</span><span class="method-args">() {|x| ...}</span>
|
323
|
+
</a>
|
324
|
+
</div>
|
325
|
+
|
326
|
+
<div class="method-description">
|
327
|
+
<p>
|
328
|
+
This allows you to easily recurse of the array randomly.
|
329
|
+
</p>
|
330
|
+
<p><a class="source-toggle" href="#"
|
331
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
332
|
+
<div class="method-source-code" id="M000013-source">
|
333
|
+
<pre>
|
334
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 70</span>
|
335
|
+
70: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">random_each</span>
|
336
|
+
71: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">randomize</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">x</span>}
|
337
|
+
72: <span class="ruby-keyword kw">end</span>
|
338
|
+
</pre>
|
339
|
+
</div>
|
340
|
+
</div>
|
341
|
+
</div>
|
342
|
+
|
343
|
+
<div id="method-M000010" class="method-detail">
|
344
|
+
<a name="M000010"></a>
|
345
|
+
|
346
|
+
<div class="method-heading">
|
347
|
+
<a href="#M000010" class="method-signature">
|
348
|
+
<span class="method-name">randomize</span><span class="method-args">() {|x, y| ...}</span>
|
349
|
+
</a>
|
350
|
+
</div>
|
351
|
+
|
352
|
+
<div class="method-description">
|
353
|
+
<p>
|
354
|
+
This will return a new instance of the array sorted randomly.
|
355
|
+
</p>
|
356
|
+
<p><a class="source-toggle" href="#"
|
357
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
358
|
+
<div class="method-source-code" id="M000010-source">
|
359
|
+
<pre>
|
360
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 47</span>
|
361
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">randomize</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
362
|
+
48: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
363
|
+
49: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">sort</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">x</span>, <span class="ruby-identifier">y</span>}
|
364
|
+
50: <span class="ruby-keyword kw">else</span>
|
365
|
+
51: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">sort_by</span> { <span class="ruby-identifier">rand</span> }
|
366
|
+
52: <span class="ruby-keyword kw">end</span>
|
367
|
+
53: <span class="ruby-keyword kw">end</span>
|
368
|
+
</pre>
|
369
|
+
</div>
|
370
|
+
</div>
|
371
|
+
</div>
|
372
|
+
|
373
|
+
<div id="method-M000011" class="method-detail">
|
374
|
+
<a name="M000011"></a>
|
375
|
+
|
376
|
+
<div class="method-heading">
|
377
|
+
<a href="#M000011" class="method-signature">
|
378
|
+
<span class="method-name">randomize!</span><span class="method-args">(&block)</span>
|
379
|
+
</a>
|
380
|
+
</div>
|
381
|
+
|
382
|
+
<div class="method-description">
|
383
|
+
<p>
|
384
|
+
This calls the <a href="Array.html#M000010">randomize</a> method, but will
|
385
|
+
permantly replace the existing array.
|
386
|
+
</p>
|
387
|
+
<p><a class="source-toggle" href="#"
|
388
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
389
|
+
<div class="method-source-code" id="M000011-source">
|
390
|
+
<pre>
|
391
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 56</span>
|
392
|
+
56: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">randomize!</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
393
|
+
57: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
394
|
+
58: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">randomize</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>))
|
395
|
+
59: <span class="ruby-keyword kw">else</span>
|
396
|
+
60: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">randomize</span>)
|
397
|
+
61: <span class="ruby-keyword kw">end</span>
|
398
|
+
62: <span class="ruby-keyword kw">end</span>
|
399
|
+
</pre>
|
400
|
+
</div>
|
401
|
+
</div>
|
402
|
+
</div>
|
403
|
+
|
404
|
+
<div id="method-M000014" class="method-detail">
|
405
|
+
<a name="M000014"></a>
|
406
|
+
|
407
|
+
<div class="method-heading">
|
408
|
+
<a href="#M000014" class="method-signature">
|
409
|
+
<span class="method-name">subset?</span><span class="method-args">(other)</span>
|
410
|
+
</a>
|
411
|
+
</div>
|
412
|
+
|
413
|
+
<div class="method-description">
|
414
|
+
<p><a class="source-toggle" href="#"
|
415
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
416
|
+
<div class="method-source-code" id="M000014-source">
|
417
|
+
<pre>
|
418
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 74</span>
|
419
|
+
74: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">subset?</span>(<span class="ruby-identifier">other</span>)
|
420
|
+
75: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
|
421
|
+
76: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">x</span>)
|
422
|
+
77: <span class="ruby-keyword kw">end</span>
|
423
|
+
78: <span class="ruby-keyword kw">true</span>
|
424
|
+
79: <span class="ruby-keyword kw">end</span>
|
425
|
+
</pre>
|
426
|
+
</div>
|
427
|
+
</div>
|
428
|
+
</div>
|
429
|
+
|
430
|
+
<div id="method-M000015" class="method-detail">
|
431
|
+
<a name="M000015"></a>
|
432
|
+
|
433
|
+
<div class="method-heading">
|
434
|
+
<a href="#M000015" class="method-signature">
|
435
|
+
<span class="method-name">superset?</span><span class="method-args">(other)</span>
|
436
|
+
</a>
|
437
|
+
</div>
|
438
|
+
|
439
|
+
<div class="method-description">
|
440
|
+
<p><a class="source-toggle" href="#"
|
441
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
442
|
+
<div class="method-source-code" id="M000015-source">
|
443
|
+
<pre>
|
444
|
+
<span class="ruby-comment cmt"># File lib/extensions/array.rb, line 81</span>
|
445
|
+
81: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">superset?</span>(<span class="ruby-identifier">other</span>)
|
446
|
+
82: <span class="ruby-identifier">other</span>.<span class="ruby-identifier">subset?</span>(<span class="ruby-keyword kw">self</span>)
|
447
|
+
83: <span class="ruby-keyword kw">end</span>
|
448
|
+
</pre>
|
449
|
+
</div>
|
450
|
+
</div>
|
451
|
+
</div>
|
452
|
+
|
453
|
+
|
454
|
+
</div>
|
455
|
+
|
456
|
+
|
457
|
+
</div>
|
458
|
+
|
459
|
+
|
460
|
+
<div id="validator-badges">
|
461
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
462
|
+
</div>
|
463
|
+
|
464
|
+
</body>
|
465
|
+
</html>
|