mack_ruby_core_extensions 0.1.25 → 0.1.26
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/lib/extensions/object.rb +16 -1
- data/lib/extensions/string.rb +25 -23
- metadata +3 -39
- data/doc/classes/Array.html +0 -465
- data/doc/classes/Class.html +0 -233
- data/doc/classes/Float.html +0 -148
- data/doc/classes/Hash.html +0 -286
- data/doc/classes/Kernel.html +0 -184
- data/doc/classes/Mack/Utils/Inflector.html +0 -422
- data/doc/classes/Math.html +0 -188
- data/doc/classes/MethodNotImplemented.html +0 -155
- data/doc/classes/Module.html +0 -203
- data/doc/classes/NilClass.html +0 -151
- data/doc/classes/Object.html +0 -472
- data/doc/classes/String.html +0 -977
- data/doc/classes/Symbol.html +0 -148
- data/doc/created.rid +0 -1
- data/doc/files/README.html +0 -151
- data/doc/files/lib/extensions/array_rb.html +0 -101
- data/doc/files/lib/extensions/class_rb.html +0 -101
- data/doc/files/lib/extensions/float_rb.html +0 -101
- data/doc/files/lib/extensions/hash_rb.html +0 -108
- data/doc/files/lib/extensions/kernel_rb.html +0 -109
- data/doc/files/lib/extensions/math_rb.html +0 -101
- data/doc/files/lib/extensions/method_not_implemented_rb.html +0 -108
- data/doc/files/lib/extensions/module_rb.html +0 -101
- data/doc/files/lib/extensions/nil_rb.html +0 -101
- data/doc/files/lib/extensions/object_rb.html +0 -101
- data/doc/files/lib/extensions/string_rb.html +0 -108
- data/doc/files/lib/extensions/symbol_rb.html +0 -101
- data/doc/files/lib/mack_ruby_core_extensions_rb.html +0 -101
- data/doc/files/lib/utils/inflections_rb.html +0 -101
- data/doc/files/lib/utils/inflector_rb.html +0 -108
- data/doc/files/lib/utils/options_merger_rb.html +0 -101
- data/doc/fr_class_index.html +0 -39
- data/doc/fr_file_index.html +0 -43
- data/doc/fr_method_index.html +0 -99
- data/doc/index.html +0 -24
- data/doc/rdoc-style.css +0 -208
data/lib/extensions/object.rb
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
class Object
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
# An elegant way to refactor out common options
|
|
4
|
+
#
|
|
5
|
+
# with_options :order => 'created_at', :class_name => 'Comment' do |post|
|
|
6
|
+
# post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
|
|
7
|
+
# post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
|
|
8
|
+
# post.has_many :all_comments
|
|
9
|
+
# end
|
|
10
|
+
#
|
|
11
|
+
# Can also be used with an explicit receiver:
|
|
12
|
+
#
|
|
13
|
+
# map.with_options :controller => "people" do |people|
|
|
14
|
+
# people.connect "/people", :action => "index"
|
|
15
|
+
# people.connect "/people/:id", :action => "show"
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
3
18
|
def with_options(options)
|
|
4
19
|
yield Mack::Utils::OptionMerger.new(self, options)
|
|
5
20
|
end
|
data/lib/extensions/string.rb
CHANGED
|
@@ -185,29 +185,31 @@ class String
|
|
|
185
185
|
# http://www.quirksmode.org/oddsandends/wbr.html
|
|
186
186
|
# http://krijnhoetmer.nl/stuff/css/word-wrap-break-word/
|
|
187
187
|
# note: if the txt has spaces, this will only try to break up runs of non-space characters longer than "every" characters
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
188
|
+
def breakify(every = 30)
|
|
189
|
+
every = 1 if every < 1
|
|
190
|
+
text = self
|
|
191
|
+
textile_regex = /([^\"]+\"):([^:]*:[\/\/]{0,1}[^ ]*)/
|
|
192
|
+
long_regex = /\S{#{every},}/
|
|
193
|
+
brokentxt = text.gsub(long_regex) do |longword|
|
|
194
|
+
if longword =~ textile_regex #if the longword is a textile link...ignore and recheck for the link text only
|
|
195
|
+
textile_link = textile_regex.match(longword)[0]
|
|
196
|
+
link_text = textile_regex.match(longword)[1]
|
|
197
|
+
longword = link_text
|
|
198
|
+
if longword =~ long_regex #link text is long...allow break
|
|
199
|
+
textile_link = '"' + textile_link unless textile_link[0].to_i == 34 #adds the double quote back if missing from above regex
|
|
200
|
+
textile_link.scan(/.{1,#{every}}/).join("<wbr/>")
|
|
201
|
+
else
|
|
202
|
+
textile_link #the url is what triggered the match...so leave it alone
|
|
203
|
+
end
|
|
204
|
+
else
|
|
205
|
+
longword.scan(/.{1,#{every}}/).join("<wbr/>") #no textile link
|
|
206
|
+
matched
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
#text = %Q[<span style='word-wrap:break-word;wbr:after{content:"\\00200B"}'>#{brokentxt}</span>]
|
|
210
|
+
#brokentxt.gsub("<wbr/>", "<br />")
|
|
211
|
+
brokentxt.gsub("<wbr/>", " ")
|
|
212
|
+
end
|
|
211
213
|
|
|
212
214
|
def breakify!(every = 30)
|
|
213
215
|
self.replace(self.breakify(every))
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mack_ruby_core_extensions
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.26
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- markbates
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-05-
|
|
12
|
+
date: 2008-05-09 00:00:00 -04:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -39,42 +39,6 @@ files:
|
|
|
39
39
|
- lib/utils/inflector.rb
|
|
40
40
|
- lib/utils/options_merger.rb
|
|
41
41
|
- README
|
|
42
|
-
- doc/classes/Array.html
|
|
43
|
-
- doc/classes/Class.html
|
|
44
|
-
- doc/classes/Float.html
|
|
45
|
-
- doc/classes/Hash.html
|
|
46
|
-
- doc/classes/Kernel.html
|
|
47
|
-
- doc/classes/Mack/Utils/Inflector.html
|
|
48
|
-
- doc/classes/Math.html
|
|
49
|
-
- doc/classes/MethodNotImplemented.html
|
|
50
|
-
- doc/classes/Module.html
|
|
51
|
-
- doc/classes/NilClass.html
|
|
52
|
-
- doc/classes/Object.html
|
|
53
|
-
- doc/classes/String.html
|
|
54
|
-
- doc/classes/Symbol.html
|
|
55
|
-
- doc/created.rid
|
|
56
|
-
- doc/files/lib/extensions/array_rb.html
|
|
57
|
-
- doc/files/lib/extensions/class_rb.html
|
|
58
|
-
- doc/files/lib/extensions/float_rb.html
|
|
59
|
-
- doc/files/lib/extensions/hash_rb.html
|
|
60
|
-
- doc/files/lib/extensions/kernel_rb.html
|
|
61
|
-
- doc/files/lib/extensions/math_rb.html
|
|
62
|
-
- doc/files/lib/extensions/method_not_implemented_rb.html
|
|
63
|
-
- doc/files/lib/extensions/module_rb.html
|
|
64
|
-
- doc/files/lib/extensions/nil_rb.html
|
|
65
|
-
- doc/files/lib/extensions/object_rb.html
|
|
66
|
-
- doc/files/lib/extensions/string_rb.html
|
|
67
|
-
- doc/files/lib/extensions/symbol_rb.html
|
|
68
|
-
- doc/files/lib/mack_ruby_core_extensions_rb.html
|
|
69
|
-
- doc/files/lib/utils/inflections_rb.html
|
|
70
|
-
- doc/files/lib/utils/inflector_rb.html
|
|
71
|
-
- doc/files/lib/utils/options_merger_rb.html
|
|
72
|
-
- doc/files/README.html
|
|
73
|
-
- doc/fr_class_index.html
|
|
74
|
-
- doc/fr_file_index.html
|
|
75
|
-
- doc/fr_method_index.html
|
|
76
|
-
- doc/index.html
|
|
77
|
-
- doc/rdoc-style.css
|
|
78
42
|
has_rdoc: true
|
|
79
43
|
homepage: http://www.mackframework.com
|
|
80
44
|
post_install_message:
|
|
@@ -103,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
103
67
|
requirements: []
|
|
104
68
|
|
|
105
69
|
rubyforge_project: magrathea
|
|
106
|
-
rubygems_version: 1.
|
|
70
|
+
rubygems_version: 1.0.1
|
|
107
71
|
signing_key:
|
|
108
72
|
specification_version: 2
|
|
109
73
|
summary: mack_ruby_core_extensions
|
data/doc/classes/Array.html
DELETED
|
@@ -1,465 +0,0 @@
|
|
|
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">flatten</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> # => {"red"
|
|
224
|
-
=> 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>
|