mack-facets 0.6.0 → 0.6.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/doc/classes/Array.html +408 -0
- data/doc/classes/Class.html +233 -0
- data/doc/classes/Hash.html +233 -0
- data/doc/classes/Kernel.html +184 -0
- data/doc/classes/Mack/Utils/Inflector.html +382 -0
- data/doc/classes/Math.html +188 -0
- data/doc/classes/Module.html +203 -0
- data/doc/classes/Object.html +558 -0
- data/doc/classes/String.html +451 -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/english_extensions/inflect_rb.html +101 -0
- data/doc/files/lib/english_extensions/numerals_rb.html +101 -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/hash_rb.html +108 -0
- data/doc/files/lib/extensions/kernel_rb.html +109 -0
- data/doc/files/lib/extensions/math_rb.html +101 -0
- data/doc/files/lib/extensions/module_rb.html +101 -0
- data/doc/files/lib/extensions/object_rb.html +101 -0
- data/doc/files/lib/extensions/string_rb.html +101 -0
- data/doc/files/lib/extensions/symbol_rb.html +101 -0
- data/doc/files/lib/mack-facets_rb.html +120 -0
- data/doc/files/lib/utils/inflections_rb.html +101 -0
- data/doc/files/lib/utils/inflector_rb.html +108 -0
- data/doc/files/lib/utils/options_merger_rb.html +101 -0
- data/doc/fr_class_index.html +36 -0
- data/doc/fr_file_index.html +42 -0
- data/doc/fr_method_index.html +75 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- metadata +37 -3
@@ -0,0 +1,188 @@
|
|
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>Module: Math</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>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Math</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/extensions/math_rb.html">
|
59
|
+
lib/extensions/math.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
<div id="method-list">
|
80
|
+
<h3 class="section-bar">Methods</h3>
|
81
|
+
|
82
|
+
<div class="name-list">
|
83
|
+
<a href="#M000047">log2</a>
|
84
|
+
<a href="#M000049">max</a>
|
85
|
+
<a href="#M000048">min</a>
|
86
|
+
</div>
|
87
|
+
</div>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
<!-- if includes -->
|
93
|
+
|
94
|
+
<div id="section">
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
<!-- if method_list -->
|
104
|
+
<div id="methods">
|
105
|
+
<h3 class="section-bar">Public Class methods</h3>
|
106
|
+
|
107
|
+
<div id="method-M000047" class="method-detail">
|
108
|
+
<a name="M000047"></a>
|
109
|
+
|
110
|
+
<div class="method-heading">
|
111
|
+
<a href="#M000047" class="method-signature">
|
112
|
+
<span class="method-name">log2</span><span class="method-args">(x)</span>
|
113
|
+
</a>
|
114
|
+
</div>
|
115
|
+
|
116
|
+
<div class="method-description">
|
117
|
+
<p><a class="source-toggle" href="#"
|
118
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
119
|
+
<div class="method-source-code" id="M000047-source">
|
120
|
+
<pre>
|
121
|
+
<span class="ruby-comment cmt"># File lib/extensions/math.rb, line 3</span>
|
122
|
+
3: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">log2</span>(<span class="ruby-identifier">x</span>)
|
123
|
+
4: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">x</span>)<span class="ruby-operator">/</span><span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">log</span>(<span class="ruby-value">2.0</span>)
|
124
|
+
5: <span class="ruby-keyword kw">end</span>
|
125
|
+
</pre>
|
126
|
+
</div>
|
127
|
+
</div>
|
128
|
+
</div>
|
129
|
+
|
130
|
+
<div id="method-M000049" class="method-detail">
|
131
|
+
<a name="M000049"></a>
|
132
|
+
|
133
|
+
<div class="method-heading">
|
134
|
+
<a href="#M000049" class="method-signature">
|
135
|
+
<span class="method-name">max</span><span class="method-args">(a, b)</span>
|
136
|
+
</a>
|
137
|
+
</div>
|
138
|
+
|
139
|
+
<div class="method-description">
|
140
|
+
<p><a class="source-toggle" href="#"
|
141
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
142
|
+
<div class="method-source-code" id="M000049-source">
|
143
|
+
<pre>
|
144
|
+
<span class="ruby-comment cmt"># File lib/extensions/math.rb, line 11</span>
|
145
|
+
11: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">max</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
|
146
|
+
12: <span class="ruby-identifier">a</span> <span class="ruby-operator">></span> <span class="ruby-identifier">b</span> <span class="ruby-value">? </span><span class="ruby-identifier">a</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">b</span>
|
147
|
+
13: <span class="ruby-keyword kw">end</span>
|
148
|
+
</pre>
|
149
|
+
</div>
|
150
|
+
</div>
|
151
|
+
</div>
|
152
|
+
|
153
|
+
<div id="method-M000048" class="method-detail">
|
154
|
+
<a name="M000048"></a>
|
155
|
+
|
156
|
+
<div class="method-heading">
|
157
|
+
<a href="#M000048" class="method-signature">
|
158
|
+
<span class="method-name">min</span><span class="method-args">(a, b)</span>
|
159
|
+
</a>
|
160
|
+
</div>
|
161
|
+
|
162
|
+
<div class="method-description">
|
163
|
+
<p><a class="source-toggle" href="#"
|
164
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
165
|
+
<div class="method-source-code" id="M000048-source">
|
166
|
+
<pre>
|
167
|
+
<span class="ruby-comment cmt"># File lib/extensions/math.rb, line 7</span>
|
168
|
+
7: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">min</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
|
169
|
+
8: <span class="ruby-identifier">a</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">b</span> <span class="ruby-value">? </span><span class="ruby-identifier">a</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">b</span>
|
170
|
+
9: <span class="ruby-keyword kw">end</span>
|
171
|
+
</pre>
|
172
|
+
</div>
|
173
|
+
</div>
|
174
|
+
</div>
|
175
|
+
|
176
|
+
|
177
|
+
</div>
|
178
|
+
|
179
|
+
|
180
|
+
</div>
|
181
|
+
|
182
|
+
|
183
|
+
<div id="validator-badges">
|
184
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
185
|
+
</div>
|
186
|
+
|
187
|
+
</body>
|
188
|
+
</html>
|
@@ -0,0 +1,203 @@
|
|
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: Module</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">Module</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/extensions/module_rb.html">
|
59
|
+
lib/extensions/module.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="#M000014">convert_security_of_methods</a>
|
92
|
+
<a href="#M000015">include_safely_into</a>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
|
96
|
+
</div>
|
97
|
+
|
98
|
+
|
99
|
+
<!-- if includes -->
|
100
|
+
|
101
|
+
<div id="section">
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<!-- if method_list -->
|
111
|
+
<div id="methods">
|
112
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
113
|
+
|
114
|
+
<div id="method-M000014" class="method-detail">
|
115
|
+
<a name="M000014"></a>
|
116
|
+
|
117
|
+
<div class="method-heading">
|
118
|
+
<a href="#M000014" class="method-signature">
|
119
|
+
<span class="method-name">convert_security_of_methods</span><span class="method-args">(old_level = :public, new_level = :protected)</span>
|
120
|
+
</a>
|
121
|
+
</div>
|
122
|
+
|
123
|
+
<div class="method-description">
|
124
|
+
<p>
|
125
|
+
Bulk converts the security level of methods in this <a
|
126
|
+
href="Module.html">Module</a> from one level to another.
|
127
|
+
</p>
|
128
|
+
<p><a class="source-toggle" href="#"
|
129
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
130
|
+
<div class="method-source-code" id="M000014-source">
|
131
|
+
<pre>
|
132
|
+
<span class="ruby-comment cmt"># File lib/extensions/module.rb, line 4</span>
|
133
|
+
4: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">convert_security_of_methods</span>(<span class="ruby-identifier">old_level</span> = <span class="ruby-identifier">:public</span>, <span class="ruby-identifier">new_level</span> = <span class="ruby-identifier">:protected</span>)
|
134
|
+
5: <span class="ruby-identifier">eval</span>(<span class="ruby-node">"#{old_level}_instance_methods"</span>).<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">meth</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">new_level</span>, <span class="ruby-identifier">meth</span>) }
|
135
|
+
6: <span class="ruby-keyword kw">self</span>
|
136
|
+
7: <span class="ruby-keyword kw">end</span>
|
137
|
+
</pre>
|
138
|
+
</div>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
|
142
|
+
<div id="method-M000015" class="method-detail">
|
143
|
+
<a name="M000015"></a>
|
144
|
+
|
145
|
+
<div class="method-heading">
|
146
|
+
<a href="#M000015" class="method-signature">
|
147
|
+
<span class="method-name">include_safely_into</span><span class="method-args">(*args)</span>
|
148
|
+
</a>
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<div class="method-description">
|
152
|
+
<p>
|
153
|
+
Includes this module into a <a href="Class.html">Class</a>, and changes all
|
154
|
+
public methods to protected.
|
155
|
+
</p>
|
156
|
+
<p>
|
157
|
+
Examples:
|
158
|
+
</p>
|
159
|
+
<pre>
|
160
|
+
module MyCoolUtils
|
161
|
+
def some_meth
|
162
|
+
"hi"
|
163
|
+
end
|
164
|
+
self.include_safely_into(FooController)
|
165
|
+
end
|
166
|
+
</pre>
|
167
|
+
<p>
|
168
|
+
or:
|
169
|
+
</p>
|
170
|
+
<pre>
|
171
|
+
MyCoolUtils.include_safely_into(FooController, SomeOtherClass)
|
172
|
+
</pre>
|
173
|
+
<p><a class="source-toggle" href="#"
|
174
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
175
|
+
<div class="method-source-code" id="M000015-source">
|
176
|
+
<pre>
|
177
|
+
<span class="ruby-comment cmt"># File lib/extensions/module.rb, line 20</span>
|
178
|
+
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_safely_into</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
179
|
+
21: [<span class="ruby-identifier">args</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
|
180
|
+
22: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
|
181
|
+
23: <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">constantize</span>
|
182
|
+
24: <span class="ruby-keyword kw">end</span>
|
183
|
+
25: <span class="ruby-identifier">a</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:include</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">convert_security_of_methods</span>)
|
184
|
+
26: <span class="ruby-keyword kw">end</span>
|
185
|
+
27: <span class="ruby-keyword kw">end</span>
|
186
|
+
</pre>
|
187
|
+
</div>
|
188
|
+
</div>
|
189
|
+
</div>
|
190
|
+
|
191
|
+
|
192
|
+
</div>
|
193
|
+
|
194
|
+
|
195
|
+
</div>
|
196
|
+
|
197
|
+
|
198
|
+
<div id="validator-badges">
|
199
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
200
|
+
</div>
|
201
|
+
|
202
|
+
</body>
|
203
|
+
</html>
|
@@ -0,0 +1,558 @@
|
|
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: Object</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">Object</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/extensions/object_rb.html">
|
59
|
+
lib/extensions/object.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="#M000022">class_parents</a>
|
92
|
+
<a href="#M000027">ivar_cache</a>
|
93
|
+
<a href="#M000028">ivar_cache_clear</a>
|
94
|
+
<a href="#M000029">namespaces</a>
|
95
|
+
<a href="#M000024">needs_method</a>
|
96
|
+
<a href="#M000020">print_methods</a>
|
97
|
+
<a href="#M000025">running_time</a>
|
98
|
+
<a href="#M000019">safely_include_module</a>
|
99
|
+
<a href="#M000026">send_with_chain</a>
|
100
|
+
<a href="#M000023">to_param</a>
|
101
|
+
<a href="#M000021">with_options</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 Class methods</h3>
|
122
|
+
|
123
|
+
<div id="method-M000024" class="method-detail">
|
124
|
+
<a name="M000024"></a>
|
125
|
+
|
126
|
+
<div class="method-heading">
|
127
|
+
<a href="#M000024" class="method-signature">
|
128
|
+
<span class="method-name">needs_method</span><span class="method-args">(meth)</span>
|
129
|
+
</a>
|
130
|
+
</div>
|
131
|
+
|
132
|
+
<div class="method-description">
|
133
|
+
<p>
|
134
|
+
Uses <tt>define_method</tt> to create an empty for the method parameter
|
135
|
+
defined. That method will then raise MethodNotImplemented. This is useful
|
136
|
+
for creating interfaces and you want to stub out methods that others need
|
137
|
+
to implement.
|
138
|
+
</p>
|
139
|
+
<p><a class="source-toggle" href="#"
|
140
|
+
onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
|
141
|
+
<div class="method-source-code" id="M000024-source">
|
142
|
+
<pre>
|
143
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 56</span>
|
144
|
+
56: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">needs_method</span>(<span class="ruby-identifier">meth</span>)
|
145
|
+
57: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">meth</span>) <span class="ruby-keyword kw">do</span>
|
146
|
+
58: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoMethodError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"The interface you are using requires you define the following method '#{meth}'"</span>)
|
147
|
+
59: <span class="ruby-keyword kw">end</span>
|
148
|
+
60: <span class="ruby-keyword kw">end</span>
|
149
|
+
</pre>
|
150
|
+
</div>
|
151
|
+
</div>
|
152
|
+
</div>
|
153
|
+
|
154
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
155
|
+
|
156
|
+
<div id="method-M000022" class="method-detail">
|
157
|
+
<a name="M000022"></a>
|
158
|
+
|
159
|
+
<div class="method-heading">
|
160
|
+
<a href="#M000022" class="method-signature">
|
161
|
+
<span class="method-name">class_parents</span><span class="method-args">()</span>
|
162
|
+
</a>
|
163
|
+
</div>
|
164
|
+
|
165
|
+
<div class="method-description">
|
166
|
+
<p>
|
167
|
+
See <a href="Class.html">Class</a> parents for more information.
|
168
|
+
</p>
|
169
|
+
<p><a class="source-toggle" href="#"
|
170
|
+
onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
|
171
|
+
<div class="method-source-code" id="M000022-source">
|
172
|
+
<pre>
|
173
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 43</span>
|
174
|
+
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_parents</span>
|
175
|
+
44: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">parents</span>
|
176
|
+
45: <span class="ruby-keyword kw">end</span>
|
177
|
+
</pre>
|
178
|
+
</div>
|
179
|
+
</div>
|
180
|
+
</div>
|
181
|
+
|
182
|
+
<div id="method-M000027" class="method-detail">
|
183
|
+
<a name="M000027"></a>
|
184
|
+
|
185
|
+
<div class="method-heading">
|
186
|
+
<a href="#M000027" class="method-signature">
|
187
|
+
<span class="method-name">ivar_cache</span><span class="method-args">(var_name = nil) {|| ...}</span>
|
188
|
+
</a>
|
189
|
+
</div>
|
190
|
+
|
191
|
+
<div class="method-description">
|
192
|
+
<p>
|
193
|
+
<a href="Object.html#M000027">ivar_cache</a> allows you to cache the
|
194
|
+
results of the block into an instance variable in a class, and then will
|
195
|
+
serve up that instance variable the next time you call that method again.
|
196
|
+
</p>
|
197
|
+
<p>
|
198
|
+
old way:
|
199
|
+
</p>
|
200
|
+
<pre>
|
201
|
+
def show_page_link
|
202
|
+
unless @show_page_link # check if instance variable exists
|
203
|
+
# if the instance variable doesn't exist let's do some work and assign it to the instance variable.
|
204
|
+
@show_page_link = link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
205
|
+
end
|
206
|
+
@show_page_link # now return the instance variable
|
207
|
+
end
|
208
|
+
</pre>
|
209
|
+
<p>
|
210
|
+
new way:
|
211
|
+
</p>
|
212
|
+
<pre>
|
213
|
+
def show_page_link
|
214
|
+
ivar_cache do
|
215
|
+
link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
216
|
+
end
|
217
|
+
end
|
218
|
+
</pre>
|
219
|
+
<p>
|
220
|
+
this does everything the old way did, but it is much cleaner, and a lot
|
221
|
+
less code! in case you‘re wondering it caches the result, by default,
|
222
|
+
to an instance variable named after the method, so in our above example the
|
223
|
+
instance variable would be name, <tt>@show_page_link</tt>. this can be
|
224
|
+
overridden like such:
|
225
|
+
</p>
|
226
|
+
<pre>
|
227
|
+
def show_page_link
|
228
|
+
ivar_cache("foo_var") do
|
229
|
+
link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
230
|
+
end
|
231
|
+
end
|
232
|
+
</pre>
|
233
|
+
<p>
|
234
|
+
now it will cache it to <tt>@foo_var</tt>
|
235
|
+
</p>
|
236
|
+
<p><a class="source-toggle" href="#"
|
237
|
+
onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
|
238
|
+
<div class="method-source-code" id="M000027-source">
|
239
|
+
<pre>
|
240
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 129</span>
|
241
|
+
129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ivar_cache</span>(<span class="ruby-identifier">var_name</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
242
|
+
130: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
|
243
|
+
131: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
|
244
|
+
132: <span class="ruby-identifier">var_name</span> = <span class="ruby-identifier">call</span>[(<span class="ruby-identifier">call</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value str">'`'</span>)<span class="ruby-operator">+</span><span class="ruby-value">1</span>)<span class="ruby-operator">...</span><span class="ruby-identifier">call</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value str">"'"</span>)]
|
245
|
+
133: <span class="ruby-keyword kw">end</span>
|
246
|
+
134: <span class="ruby-identifier">var</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">"@#{var_name}"</span>)
|
247
|
+
135: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">var</span>
|
248
|
+
136: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">"@#{var_name}"</span>, <span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
249
|
+
137: <span class="ruby-keyword kw">end</span>
|
250
|
+
138: <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">"@#{var_name}"</span>)
|
251
|
+
139: <span class="ruby-keyword kw">end</span>
|
252
|
+
</pre>
|
253
|
+
</div>
|
254
|
+
</div>
|
255
|
+
</div>
|
256
|
+
|
257
|
+
<div id="method-M000028" class="method-detail">
|
258
|
+
<a name="M000028"></a>
|
259
|
+
|
260
|
+
<div class="method-heading">
|
261
|
+
<a href="#M000028" class="method-signature">
|
262
|
+
<span class="method-name">ivar_cache_clear</span><span class="method-args">(var_name = nil) {|if block_given?| ...}</span>
|
263
|
+
</a>
|
264
|
+
</div>
|
265
|
+
|
266
|
+
<div class="method-description">
|
267
|
+
<p><a class="source-toggle" href="#"
|
268
|
+
onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
|
269
|
+
<div class="method-source-code" id="M000028-source">
|
270
|
+
<pre>
|
271
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 141</span>
|
272
|
+
141: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ivar_cache_clear</span>(<span class="ruby-identifier">var_name</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
273
|
+
142: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
|
274
|
+
143: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
|
275
|
+
144: <span class="ruby-identifier">var_name</span> = <span class="ruby-identifier">call</span>[(<span class="ruby-identifier">call</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value str">'`'</span>)<span class="ruby-operator">+</span><span class="ruby-value">1</span>)<span class="ruby-operator">...</span><span class="ruby-identifier">call</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value str">"'"</span>)]
|
276
|
+
145: <span class="ruby-keyword kw">end</span>
|
277
|
+
146: <span class="ruby-identifier">remove_instance_variable</span>(<span class="ruby-node">"@#{var_name}"</span>) <span class="ruby-comment cmt">#rescue</span>
|
278
|
+
147: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
279
|
+
148: <span class="ruby-keyword kw">end</span>
|
280
|
+
</pre>
|
281
|
+
</div>
|
282
|
+
</div>
|
283
|
+
</div>
|
284
|
+
|
285
|
+
<div id="method-M000029" class="method-detail">
|
286
|
+
<a name="M000029"></a>
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
<a href="#M000029" class="method-signature">
|
290
|
+
<span class="method-name">namespaces</span><span class="method-args">()</span>
|
291
|
+
</a>
|
292
|
+
</div>
|
293
|
+
|
294
|
+
<div class="method-description">
|
295
|
+
<p>
|
296
|
+
Returns the <a href="Object.html#M000029">namespaces</a> for a particular
|
297
|
+
object.
|
298
|
+
</p>
|
299
|
+
<p>
|
300
|
+
Examples:
|
301
|
+
</p>
|
302
|
+
<pre>
|
303
|
+
Animals::Dog::Poodle.new.namespaces # => ["Animals", "Dog"]
|
304
|
+
</pre>
|
305
|
+
<p><a class="source-toggle" href="#"
|
306
|
+
onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
|
307
|
+
<div class="method-source-code" id="M000029-source">
|
308
|
+
<pre>
|
309
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 154</span>
|
310
|
+
154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">namespaces</span>
|
311
|
+
155: <span class="ruby-identifier">ivar_cache</span>(<span class="ruby-value str">"object_namespaces"</span>) <span class="ruby-keyword kw">do</span>
|
312
|
+
156: <span class="ruby-identifier">nss</span> = []
|
313
|
+
157: <span class="ruby-identifier">full_name</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>
|
314
|
+
158: <span class="ruby-identifier">nss</span> = <span class="ruby-identifier">full_name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">"::"</span>)
|
315
|
+
159: <span class="ruby-identifier">nss</span>.<span class="ruby-identifier">pop</span>
|
316
|
+
160: <span class="ruby-identifier">nss</span>
|
317
|
+
161: <span class="ruby-keyword kw">end</span>
|
318
|
+
162: <span class="ruby-keyword kw">end</span>
|
319
|
+
</pre>
|
320
|
+
</div>
|
321
|
+
</div>
|
322
|
+
</div>
|
323
|
+
|
324
|
+
<div id="method-M000020" class="method-detail">
|
325
|
+
<a name="M000020"></a>
|
326
|
+
|
327
|
+
<div class="method-heading">
|
328
|
+
<a href="#M000020" class="method-signature">
|
329
|
+
<span class="method-name">print_methods</span><span class="method-args">()</span>
|
330
|
+
</a>
|
331
|
+
</div>
|
332
|
+
|
333
|
+
<div class="method-description">
|
334
|
+
<p>
|
335
|
+
Prints out the methods associated with this object in alphabetical order.
|
336
|
+
</p>
|
337
|
+
<p><a class="source-toggle" href="#"
|
338
|
+
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
339
|
+
<div class="method-source-code" id="M000020-source">
|
340
|
+
<pre>
|
341
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 16</span>
|
342
|
+
16: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_methods</span>
|
343
|
+
17: <span class="ruby-identifier">m</span> = <span class="ruby-node">"----- #{self} (methods) -----\n"</span>
|
344
|
+
18: <span class="ruby-identifier">m</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"\n"</span>)
|
345
|
+
19: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">m</span>
|
346
|
+
20: <span class="ruby-identifier">m</span>
|
347
|
+
21: <span class="ruby-keyword kw">end</span>
|
348
|
+
</pre>
|
349
|
+
</div>
|
350
|
+
</div>
|
351
|
+
</div>
|
352
|
+
|
353
|
+
<div id="method-M000025" class="method-detail">
|
354
|
+
<a name="M000025"></a>
|
355
|
+
|
356
|
+
<div class="method-heading">
|
357
|
+
<a href="#M000025" class="method-signature">
|
358
|
+
<span class="method-name">running_time</span><span class="method-args">(message = "", logger = nil) {|if block_given?| ...}</span>
|
359
|
+
</a>
|
360
|
+
</div>
|
361
|
+
|
362
|
+
<div class="method-description">
|
363
|
+
<p>
|
364
|
+
This prints out running time for the block provided. This is great for
|
365
|
+
things like Rake tasks, etc… where you would like to know how long
|
366
|
+
it, or a section of it took to run.
|
367
|
+
</p>
|
368
|
+
<p><a class="source-toggle" href="#"
|
369
|
+
onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
|
370
|
+
<div class="method-source-code" id="M000025-source">
|
371
|
+
<pre>
|
372
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 65</span>
|
373
|
+
65: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">running_time</span>(<span class="ruby-identifier">message</span> = <span class="ruby-value str">""</span>, <span class="ruby-identifier">logger</span> = <span class="ruby-keyword kw">nil</span>)
|
374
|
+
66: <span class="ruby-identifier">s_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
375
|
+
67: <span class="ruby-identifier">s</span> = <span class="ruby-node">"---Starting at #{s_time}---"</span>
|
376
|
+
68: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>
|
377
|
+
69: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">s</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">nil?</span>
|
378
|
+
70: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
379
|
+
71: <span class="ruby-identifier">e_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
380
|
+
72: <span class="ruby-identifier">e</span> = <span class="ruby-node">"---Ending at #{e_time}---"</span>
|
381
|
+
73: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>
|
382
|
+
74: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">nil?</span>
|
383
|
+
75: <span class="ruby-identifier">secs</span> = <span class="ruby-identifier">e_time</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">s_time</span>
|
384
|
+
76: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator"><</span> <span class="ruby-value">60</span>
|
385
|
+
77: <span class="ruby-identifier">x</span> = <span class="ruby-node">"Running time #{secs} seconds."</span>
|
386
|
+
78: <span class="ruby-keyword kw">else</span>
|
387
|
+
79: <span class="ruby-identifier">x</span> = <span class="ruby-node">"Running time roughly #{secs/60} minutes [#{secs} seconds]"</span>
|
388
|
+
80: <span class="ruby-keyword kw">end</span>
|
389
|
+
81: <span class="ruby-identifier">x</span> <span class="ruby-operator">+=</span> <span class="ruby-node">" [MESSAGE]: #{message}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">message</span>.<span class="ruby-identifier">blank?</span>
|
390
|
+
82: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">x</span>
|
391
|
+
83: <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">x</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">nil?</span>
|
392
|
+
84: <span class="ruby-keyword kw">end</span>
|
393
|
+
</pre>
|
394
|
+
</div>
|
395
|
+
</div>
|
396
|
+
</div>
|
397
|
+
|
398
|
+
<div id="method-M000019" class="method-detail">
|
399
|
+
<a name="M000019"></a>
|
400
|
+
|
401
|
+
<div class="method-heading">
|
402
|
+
<a href="#M000019" class="method-signature">
|
403
|
+
<span class="method-name">safely_include_module</span><span class="method-args">(*modules)</span>
|
404
|
+
</a>
|
405
|
+
</div>
|
406
|
+
|
407
|
+
<div class="method-description">
|
408
|
+
<p>
|
409
|
+
Includes a module into the current <a href="Class.html">Class</a>, and
|
410
|
+
changes all the module‘s public methods to protected.
|
411
|
+
</p>
|
412
|
+
<p>
|
413
|
+
Example:
|
414
|
+
</p>
|
415
|
+
<pre>
|
416
|
+
class FooController
|
417
|
+
safely_include_module(MyCoolUtils, MyOtherModule)
|
418
|
+
end
|
419
|
+
</pre>
|
420
|
+
<p><a class="source-toggle" href="#"
|
421
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
422
|
+
<div class="method-source-code" id="M000019-source">
|
423
|
+
<pre>
|
424
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 9</span>
|
425
|
+
9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">safely_include_module</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">modules</span>)
|
426
|
+
10: [<span class="ruby-identifier">modules</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mod</span><span class="ruby-operator">|</span>
|
427
|
+
11: <span class="ruby-identifier">mod</span>.<span class="ruby-identifier">include_safely_into</span>(<span class="ruby-keyword kw">self</span>)
|
428
|
+
12: <span class="ruby-keyword kw">end</span>
|
429
|
+
13: <span class="ruby-keyword kw">end</span>
|
430
|
+
</pre>
|
431
|
+
</div>
|
432
|
+
</div>
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<div id="method-M000026" class="method-detail">
|
436
|
+
<a name="M000026"></a>
|
437
|
+
|
438
|
+
<div class="method-heading">
|
439
|
+
<a href="#M000026" class="method-signature">
|
440
|
+
<span class="method-name">send_with_chain</span><span class="method-args">(methods, *args)</span>
|
441
|
+
</a>
|
442
|
+
</div>
|
443
|
+
|
444
|
+
<div class="method-description">
|
445
|
+
<p>
|
446
|
+
This method will call send to all the methods defined on the previous
|
447
|
+
method.
|
448
|
+
</p>
|
449
|
+
<p>
|
450
|
+
Example:
|
451
|
+
</p>
|
452
|
+
<pre>
|
453
|
+
Fruit.send_with_chain([:new, :get_citrus, :get_orange, :class]) # => Orange
|
454
|
+
</pre>
|
455
|
+
<p>
|
456
|
+
This would be the equivalent:
|
457
|
+
</p>
|
458
|
+
<pre>
|
459
|
+
Fruit.new.get_citrus.get_orange.class
|
460
|
+
</pre>
|
461
|
+
<p><a class="source-toggle" href="#"
|
462
|
+
onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
|
463
|
+
<div class="method-source-code" id="M000026-source">
|
464
|
+
<pre>
|
465
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 93</span>
|
466
|
+
93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_with_chain</span>(<span class="ruby-identifier">methods</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
467
|
+
94: <span class="ruby-identifier">obj</span> = <span class="ruby-keyword kw">self</span>
|
468
|
+
95: [<span class="ruby-identifier">methods</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">m</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)}
|
469
|
+
96: <span class="ruby-identifier">obj</span>
|
470
|
+
97: <span class="ruby-keyword kw">end</span>
|
471
|
+
</pre>
|
472
|
+
</div>
|
473
|
+
</div>
|
474
|
+
</div>
|
475
|
+
|
476
|
+
<div id="method-M000023" class="method-detail">
|
477
|
+
<a name="M000023"></a>
|
478
|
+
|
479
|
+
<div class="method-heading">
|
480
|
+
<a href="#M000023" class="method-signature">
|
481
|
+
<span class="method-name">to_param</span><span class="method-args">()</span>
|
482
|
+
</a>
|
483
|
+
</div>
|
484
|
+
|
485
|
+
<div class="method-description">
|
486
|
+
<p>
|
487
|
+
This method gets called when a parameter is passed into a named route. This
|
488
|
+
can be overridden in an <a href="Object.html">Object</a> to provlde custom
|
489
|
+
handling of parameters.
|
490
|
+
</p>
|
491
|
+
<p><a class="source-toggle" href="#"
|
492
|
+
onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
|
493
|
+
<div class="method-source-code" id="M000023-source">
|
494
|
+
<pre>
|
495
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 49</span>
|
496
|
+
49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_param</span>
|
497
|
+
50: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>
|
498
|
+
51: <span class="ruby-keyword kw">end</span>
|
499
|
+
</pre>
|
500
|
+
</div>
|
501
|
+
</div>
|
502
|
+
</div>
|
503
|
+
|
504
|
+
<div id="method-M000021" class="method-detail">
|
505
|
+
<a name="M000021"></a>
|
506
|
+
|
507
|
+
<div class="method-heading">
|
508
|
+
<a href="#M000021" class="method-signature">
|
509
|
+
<span class="method-name">with_options</span><span class="method-args">(options) {|Mack::Utils::OptionMerger.new(self, options)| ...}</span>
|
510
|
+
</a>
|
511
|
+
</div>
|
512
|
+
|
513
|
+
<div class="method-description">
|
514
|
+
<p>
|
515
|
+
An elegant way to refactor out common options
|
516
|
+
</p>
|
517
|
+
<pre>
|
518
|
+
with_options :order => 'created_at', :class_name => 'Comment' do |post|
|
519
|
+
post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
|
520
|
+
post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
|
521
|
+
post.has_many :all_comments
|
522
|
+
end
|
523
|
+
</pre>
|
524
|
+
<p>
|
525
|
+
Can also be used with an explicit receiver:
|
526
|
+
</p>
|
527
|
+
<pre>
|
528
|
+
map.with_options :controller => "people" do |people|
|
529
|
+
people.connect "/people", :action => "index"
|
530
|
+
people.connect "/people/:id", :action => "show"
|
531
|
+
end
|
532
|
+
</pre>
|
533
|
+
<p><a class="source-toggle" href="#"
|
534
|
+
onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
|
535
|
+
<div class="method-source-code" id="M000021-source">
|
536
|
+
<pre>
|
537
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 38</span>
|
538
|
+
38: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">with_options</span>(<span class="ruby-identifier">options</span>)
|
539
|
+
39: <span class="ruby-keyword kw">yield</span> <span class="ruby-constant">Mack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span><span class="ruby-operator">::</span><span class="ruby-constant">OptionMerger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">options</span>)
|
540
|
+
40: <span class="ruby-keyword kw">end</span>
|
541
|
+
</pre>
|
542
|
+
</div>
|
543
|
+
</div>
|
544
|
+
</div>
|
545
|
+
|
546
|
+
|
547
|
+
</div>
|
548
|
+
|
549
|
+
|
550
|
+
</div>
|
551
|
+
|
552
|
+
|
553
|
+
<div id="validator-badges">
|
554
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
555
|
+
</div>
|
556
|
+
|
557
|
+
</body>
|
558
|
+
</html>
|