mack_ruby_core_extensions 0.0.5 → 0.1.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/Hash.html +41 -41
- data/doc/classes/Kernel.html +12 -10
- data/doc/classes/Object.html +146 -68
- data/doc/created.rid +1 -1
- data/doc/files/README.html +1 -1
- data/doc/files/lib/extensions/array_rb.html +1 -1
- data/doc/files/lib/extensions/class_rb.html +1 -1
- data/doc/files/lib/extensions/float_rb.html +1 -1
- data/doc/files/lib/extensions/hash_rb.html +8 -1
- data/doc/files/lib/extensions/kernel_rb.html +1 -1
- data/doc/files/lib/extensions/math_rb.html +1 -1
- data/doc/files/lib/extensions/method_not_implemented_rb.html +1 -1
- data/doc/files/lib/extensions/module_rb.html +1 -1
- data/doc/files/lib/extensions/nil_rb.html +1 -1
- data/doc/files/lib/extensions/object_rb.html +1 -1
- data/doc/files/lib/extensions/string_rb.html +1 -1
- data/doc/files/lib/extensions/symbol_rb.html +1 -1
- data/doc/files/lib/mack_ruby_core_extensions_rb.html +1 -1
- data/doc/files/lib/utils/inflections_rb.html +1 -1
- data/doc/files/lib/utils/inflector_rb.html +1 -1
- data/doc/fr_file_index.html +0 -1
- data/lib/extensions/hash.rb +3 -2
- data/lib/extensions/kernel.rb +6 -2
- data/lib/extensions/object.rb +50 -39
- data/lib/mack_ruby_core_extensions.rb +1 -1
- data/test/extensions/float_test.rb +2 -0
- data/test/extensions/hash_test.rb +23 -7
- data/test/extensions/kernel_test.rb +9 -6
- data/test/extensions/math_test.rb +20 -5
- data/test/extensions/module_test.rb +0 -6
- data/test/extensions/nil_test.rb +0 -6
- data/test/extensions/object_test.rb +30 -6
- data/test/test_helper.rb +41 -0
- metadata +2 -6
- data/doc/files/lib/extensions/logger_rb.html +0 -101
- data/lib/extensions/logger.rb +0 -0
- data/test/extensions/logger_test.rb +0 -15
- data/test/extensions/method_not_implemented_test.rb +0 -15
data/doc/classes/Hash.html
CHANGED
@@ -129,11 +129,11 @@ Deletes the key(s) passed in from the hash.
|
|
129
129
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
130
130
|
<div class="method-source-code" id="M000003-source">
|
131
131
|
<pre>
|
132
|
-
<span class="ruby-comment cmt"># File lib/extensions/hash.rb, line
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
<span class="ruby-comment cmt"># File lib/extensions/hash.rb, line 13</span>
|
133
|
+
13: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-</span>(<span class="ruby-identifier">ars</span>)
|
134
|
+
14: [<span class="ruby-identifier">ars</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">a</span>)}
|
135
|
+
15: <span class="ruby-keyword kw">self</span>
|
136
|
+
16: <span class="ruby-keyword kw">end</span>
|
137
137
|
</pre>
|
138
138
|
</div>
|
139
139
|
</div>
|
@@ -153,14 +153,14 @@ Deletes the key(s) passed in from the hash.
|
|
153
153
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
154
154
|
<div class="method-source-code" id="M000002-source">
|
155
155
|
<pre>
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
156
|
+
<span class="ruby-comment cmt"># File lib/extensions/hash.rb, line 4</span>
|
157
|
+
4: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">join</span>(<span class="ruby-identifier">pair_string</span>, <span class="ruby-identifier">join_string</span>)
|
158
|
+
5: <span class="ruby-identifier">a</span> = []
|
159
|
+
6: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
160
|
+
7: <span class="ruby-identifier">a</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">sprintf</span>(<span class="ruby-identifier">pair_string</span>, <span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span>)
|
161
|
+
8: <span class="ruby-keyword kw">end</span>
|
162
|
+
9: <span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">join_string</span>)
|
163
|
+
10: <span class="ruby-keyword kw">end</span>
|
164
164
|
</pre>
|
165
165
|
</div>
|
166
166
|
</div>
|
@@ -184,34 +184,34 @@ values if true, which is the default.
|
|
184
184
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
185
185
|
<div class="method-source-code" id="M000004-source">
|
186
186
|
<pre>
|
187
|
-
<span class="ruby-comment cmt"># File lib/extensions/hash.rb, line
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
187
|
+
<span class="ruby-comment cmt"># File lib/extensions/hash.rb, line 20</span>
|
188
|
+
20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_params</span>(<span class="ruby-identifier">escape</span> = <span class="ruby-keyword kw">true</span>)
|
189
|
+
21: <span class="ruby-identifier">params</span> = <span class="ruby-value str">''</span>
|
190
|
+
22: <span class="ruby-identifier">stack</span> = []
|
191
|
+
23:
|
192
|
+
24: <span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
193
|
+
25: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
194
|
+
26: <span class="ruby-identifier">stack</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>]
|
195
|
+
27: <span class="ruby-keyword kw">else</span>
|
196
|
+
28: <span class="ruby-identifier">v</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">escape</span>
|
197
|
+
29: <span class="ruby-identifier">params</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"#{k}=#{v}&"</span>
|
198
|
+
30: <span class="ruby-keyword kw">end</span>
|
199
|
+
31: <span class="ruby-keyword kw">end</span>
|
200
|
+
32:
|
201
|
+
33: <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">parent</span>, <span class="ruby-identifier">hash</span><span class="ruby-operator">|</span>
|
202
|
+
34: <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
203
|
+
35: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
|
204
|
+
36: <span class="ruby-identifier">stack</span> <span class="ruby-operator"><<</span> [<span class="ruby-node">"#{parent}[#{k}]"</span>, <span class="ruby-identifier">v</span>]
|
205
|
+
37: <span class="ruby-keyword kw">else</span>
|
206
|
+
38: <span class="ruby-identifier">v</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">v</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">escape</span>
|
207
|
+
39: <span class="ruby-identifier">params</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"#{parent}[#{k}]=#{v}&"</span>
|
208
|
+
40: <span class="ruby-keyword kw">end</span>
|
209
|
+
41: <span class="ruby-keyword kw">end</span>
|
210
|
+
42: <span class="ruby-keyword kw">end</span>
|
211
|
+
43:
|
212
|
+
44: <span class="ruby-identifier">params</span>.<span class="ruby-identifier">chop!</span> <span class="ruby-comment cmt"># trailing &</span>
|
213
|
+
45: <span class="ruby-identifier">params</span>
|
214
|
+
46: <span class="ruby-keyword kw">end</span>
|
215
215
|
</pre>
|
216
216
|
</div>
|
217
217
|
</div>
|
data/doc/classes/Kernel.html
CHANGED
@@ -101,7 +101,7 @@
|
|
101
101
|
|
102
102
|
<!-- if method_list -->
|
103
103
|
<div id="methods">
|
104
|
-
<h3 class="section-bar">Public
|
104
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
105
105
|
|
106
106
|
<div id="method-M000062" class="method-detail">
|
107
107
|
<a name="M000062"></a>
|
@@ -118,7 +118,7 @@
|
|
118
118
|
<div class="method-source-code" id="M000062-source">
|
119
119
|
<pre>
|
120
120
|
<span class="ruby-comment cmt"># File lib/extensions/kernel.rb, line 6</span>
|
121
|
-
6: <span class="ruby-keyword kw">def</span> <span class="ruby-
|
121
|
+
6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pp_to_s</span>(<span class="ruby-identifier">object</span>)
|
122
122
|
7: <span class="ruby-identifier">pp_out</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
|
123
123
|
8: <span class="ruby-constant">PP</span>.<span class="ruby-identifier">pp</span>(<span class="ruby-identifier">object</span>,<span class="ruby-identifier">pp_out</span>)
|
124
124
|
9: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">pp_out</span>.<span class="ruby-identifier">string</span>
|
@@ -128,8 +128,6 @@
|
|
128
128
|
</div>
|
129
129
|
</div>
|
130
130
|
|
131
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
132
|
-
|
133
131
|
<div id="method-M000063" class="method-detail">
|
134
132
|
<a name="M000063"></a>
|
135
133
|
|
@@ -156,12 +154,16 @@
|
|
156
154
|
20: return yield
|
157
155
|
21: rescue #{retry_exceptions.join(", ")} => e
|
158
156
|
22: retries -= 1
|
159
|
-
23:
|
160
|
-
24:
|
161
|
-
25:
|
162
|
-
26:
|
163
|
-
27:
|
164
|
-
28:
|
157
|
+
23: if retries > 0
|
158
|
+
24: retry
|
159
|
+
25: else
|
160
|
+
26: raise e
|
161
|
+
27: end
|
162
|
+
28: end
|
163
|
+
29: }</span>
|
164
|
+
30:
|
165
|
+
31: <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">x</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
166
|
+
32: <span class="ruby-keyword kw">end</span>
|
165
167
|
</pre>
|
166
168
|
</div>
|
167
169
|
</div>
|
data/doc/classes/Object.html
CHANGED
@@ -126,16 +126,23 @@
|
|
126
126
|
</div>
|
127
127
|
|
128
128
|
<div class="method-description">
|
129
|
+
<p>
|
130
|
+
Uses <tt>define_method</tt> to create an empty for the method parameter
|
131
|
+
defined. That method will then raise <a
|
132
|
+
href="MethodNotImplemented.html">MethodNotImplemented</a>. This is useful
|
133
|
+
for creating interfaces and you want to stub out methods that others need
|
134
|
+
to implement.
|
135
|
+
</p>
|
129
136
|
<p><a class="source-toggle" href="#"
|
130
137
|
onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
|
131
138
|
<div class="method-source-code" id="M000024-source">
|
132
139
|
<pre>
|
133
|
-
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
140
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 12</span>
|
141
|
+
12: <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>)
|
142
|
+
13: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">meth</span>) <span class="ruby-keyword kw">do</span>
|
143
|
+
14: <span class="ruby-identifier">raise</span> <span class="ruby-constant">MethodNotImplemented</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">meth</span>)
|
144
|
+
15: <span class="ruby-keyword kw">end</span>
|
145
|
+
16: <span class="ruby-keyword kw">end</span>
|
139
146
|
</pre>
|
140
147
|
</div>
|
141
148
|
</div>
|
@@ -153,22 +160,66 @@
|
|
153
160
|
</div>
|
154
161
|
|
155
162
|
<div class="method-description">
|
163
|
+
<p>
|
164
|
+
<a href="Object.html#M000027">ivar_cache</a> allows you to cache the
|
165
|
+
results of the block into an instance variable in a class, and then will
|
166
|
+
serve up that instance variable the next time you call that method again.
|
167
|
+
</p>
|
168
|
+
<p>
|
169
|
+
old way:
|
170
|
+
</p>
|
171
|
+
<pre>
|
172
|
+
def show_page_link
|
173
|
+
unless @show_page_link # check if instance variable exists
|
174
|
+
# if the instance variable doesn't exist let's do some work and assign it to the instance variable.
|
175
|
+
@show_page_link = link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
176
|
+
end
|
177
|
+
@show_page_link # now return the instance variable
|
178
|
+
end
|
179
|
+
</pre>
|
180
|
+
<p>
|
181
|
+
new way:
|
182
|
+
</p>
|
183
|
+
<pre>
|
184
|
+
def show_page_link
|
185
|
+
ivar_cache do
|
186
|
+
link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
187
|
+
end
|
188
|
+
end
|
189
|
+
</pre>
|
190
|
+
<p>
|
191
|
+
this does everything the old way did, but it is much cleaner, and a lot
|
192
|
+
less code! in case you‘re wondering it caches the result, by default,
|
193
|
+
to an instance variable named after the method, so in our above example the
|
194
|
+
instance variable would be name, <tt>@show_page_link</tt>. this can be
|
195
|
+
overridden like such:
|
196
|
+
</p>
|
197
|
+
<pre>
|
198
|
+
def show_page_link
|
199
|
+
ivar_cache("foo_var") do
|
200
|
+
link_to("show", some_url(:id => self.id, :foo => bar, etc... => etc))
|
201
|
+
end
|
202
|
+
end
|
203
|
+
</pre>
|
204
|
+
<p>
|
205
|
+
now it will cache it to <tt>@foo_var</tt>
|
206
|
+
</p>
|
156
207
|
<p><a class="source-toggle" href="#"
|
157
208
|
onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
|
158
209
|
<div class="method-source-code" id="M000027-source">
|
159
210
|
<pre>
|
160
|
-
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
211
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 85</span>
|
212
|
+
85: <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>)
|
213
|
+
86: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
|
214
|
+
87: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
|
215
|
+
88: <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>)]
|
216
|
+
89: <span class="ruby-keyword kw">end</span>
|
217
|
+
90: <span class="ruby-identifier">var</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">"@#{var_name}"</span>)
|
218
|
+
91: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">var</span>
|
219
|
+
92: <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>
|
220
|
+
93: <span class="ruby-keyword kw">end</span>
|
221
|
+
94: <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">"@#{var_name}"</span>)
|
222
|
+
95: <span class="ruby-keyword kw">end</span>
|
172
223
|
</pre>
|
173
224
|
</div>
|
174
225
|
</div>
|
@@ -188,15 +239,15 @@
|
|
188
239
|
onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
|
189
240
|
<div class="method-source-code" id="M000028-source">
|
190
241
|
<pre>
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
242
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 97</span>
|
243
|
+
97: <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>)
|
244
|
+
98: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
|
245
|
+
99: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
|
246
|
+
100: <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>)]
|
247
|
+
101: <span class="ruby-keyword kw">end</span>
|
248
|
+
102: <span class="ruby-identifier">remove_instance_variable</span>(<span class="ruby-node">"@#{var_name}"</span>) <span class="ruby-comment cmt">#rescue</span>
|
249
|
+
103: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
250
|
+
104: <span class="ruby-keyword kw">end</span>
|
200
251
|
</pre>
|
201
252
|
</div>
|
202
253
|
</div>
|
@@ -212,23 +263,30 @@
|
|
212
263
|
</div>
|
213
264
|
|
214
265
|
<div class="method-description">
|
266
|
+
<p>
|
267
|
+
Returns the <a href="Object.html#M000029">namespaces</a> for a particular
|
268
|
+
object.
|
269
|
+
</p>
|
270
|
+
<p>
|
271
|
+
Examples:
|
272
|
+
</p>
|
273
|
+
<pre>
|
274
|
+
Animals::Dog::Poodle.new.namespaces # => ["Animals", "Dog"]
|
275
|
+
</pre>
|
215
276
|
<p><a class="source-toggle" href="#"
|
216
277
|
onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
|
217
278
|
<div class="method-source-code" id="M000029-source">
|
218
279
|
<pre>
|
219
|
-
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
105: <span class="ruby-identifier">nss</span>
|
230
|
-
106: <span class="ruby-keyword kw">end</span>
|
231
|
-
107: <span class="ruby-keyword kw">end</span>
|
280
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 110</span>
|
281
|
+
110: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">namespaces</span>
|
282
|
+
111: <span class="ruby-identifier">ivar_cache</span>(<span class="ruby-value str">"object_namespaces"</span>) <span class="ruby-keyword kw">do</span>
|
283
|
+
112: <span class="ruby-identifier">nss</span> = []
|
284
|
+
113: <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>
|
285
|
+
114: <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>)
|
286
|
+
115: <span class="ruby-identifier">nss</span>.<span class="ruby-identifier">pop</span>
|
287
|
+
116: <span class="ruby-identifier">nss</span>
|
288
|
+
117: <span class="ruby-keyword kw">end</span>
|
289
|
+
118: <span class="ruby-keyword kw">end</span>
|
232
290
|
</pre>
|
233
291
|
</div>
|
234
292
|
</div>
|
@@ -244,31 +302,36 @@
|
|
244
302
|
</div>
|
245
303
|
|
246
304
|
<div class="method-description">
|
305
|
+
<p>
|
306
|
+
This prints out running time for the block provided. This is great for
|
307
|
+
things like Rake tasks, etc… where you would like to know how long
|
308
|
+
it, or a section of it took to run.
|
309
|
+
</p>
|
247
310
|
<p><a class="source-toggle" href="#"
|
248
311
|
onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
|
249
312
|
<div class="method-source-code" id="M000025-source">
|
250
313
|
<pre>
|
251
|
-
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
314
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 21</span>
|
315
|
+
21: <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>)
|
316
|
+
22: <span class="ruby-identifier">s_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
317
|
+
23: <span class="ruby-identifier">s</span> = <span class="ruby-node">"---Starting at #{s_time}---"</span>
|
318
|
+
24: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>
|
319
|
+
25: <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>
|
320
|
+
26: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
321
|
+
27: <span class="ruby-identifier">e_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
|
322
|
+
28: <span class="ruby-identifier">e</span> = <span class="ruby-node">"---Ending at #{e_time}---"</span>
|
323
|
+
29: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>
|
324
|
+
30: <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>
|
325
|
+
31: <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>
|
326
|
+
32: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator"><</span> <span class="ruby-value">60</span>
|
327
|
+
33: <span class="ruby-identifier">x</span> = <span class="ruby-node">"Running time #{secs} seconds."</span>
|
328
|
+
34: <span class="ruby-keyword kw">else</span>
|
329
|
+
35: <span class="ruby-identifier">x</span> = <span class="ruby-node">"Running time roughly #{secs/60} minutes [#{secs} seconds]"</span>
|
330
|
+
36: <span class="ruby-keyword kw">end</span>
|
331
|
+
37: <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>
|
332
|
+
38: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">x</span>
|
333
|
+
39: <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>
|
334
|
+
40: <span class="ruby-keyword kw">end</span>
|
272
335
|
</pre>
|
273
336
|
</div>
|
274
337
|
</div>
|
@@ -284,17 +347,32 @@
|
|
284
347
|
</div>
|
285
348
|
|
286
349
|
<div class="method-description">
|
350
|
+
<p>
|
351
|
+
This method will call send to all the methods defined on the previous
|
352
|
+
method.
|
353
|
+
</p>
|
354
|
+
<p>
|
355
|
+
Example:
|
356
|
+
</p>
|
357
|
+
<pre>
|
358
|
+
Fruit.send_with_chain([:new, :get_citrus, :get_orange, :class]) # => Orange
|
359
|
+
</pre>
|
360
|
+
<p>
|
361
|
+
This would be the equivalent:
|
362
|
+
</p>
|
363
|
+
<pre>
|
364
|
+
Fruit.new.get_citrus.get_orange.class
|
365
|
+
</pre>
|
287
366
|
<p><a class="source-toggle" href="#"
|
288
367
|
onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
|
289
368
|
<div class="method-source-code" id="M000026-source">
|
290
369
|
<pre>
|
291
|
-
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
41: <span class="ruby-keyword kw">end</span>
|
370
|
+
<span class="ruby-comment cmt"># File lib/extensions/object.rb, line 49</span>
|
371
|
+
49: <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>)
|
372
|
+
50: <span class="ruby-identifier">obj</span> = <span class="ruby-keyword kw">self</span>
|
373
|
+
51: [<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>)}
|
374
|
+
52: <span class="ruby-identifier">obj</span>
|
375
|
+
53: <span class="ruby-keyword kw">end</span>
|
298
376
|
</pre>
|
299
377
|
</div>
|
300
378
|
</div>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Wed, 26 Mar 2008 19:20:19 -0400
|
data/doc/files/README.html
CHANGED