mack_ruby_core_extensions 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/doc/classes/Hash.html +41 -41
  2. data/doc/classes/Kernel.html +12 -10
  3. data/doc/classes/Object.html +146 -68
  4. data/doc/created.rid +1 -1
  5. data/doc/files/README.html +1 -1
  6. data/doc/files/lib/extensions/array_rb.html +1 -1
  7. data/doc/files/lib/extensions/class_rb.html +1 -1
  8. data/doc/files/lib/extensions/float_rb.html +1 -1
  9. data/doc/files/lib/extensions/hash_rb.html +8 -1
  10. data/doc/files/lib/extensions/kernel_rb.html +1 -1
  11. data/doc/files/lib/extensions/math_rb.html +1 -1
  12. data/doc/files/lib/extensions/method_not_implemented_rb.html +1 -1
  13. data/doc/files/lib/extensions/module_rb.html +1 -1
  14. data/doc/files/lib/extensions/nil_rb.html +1 -1
  15. data/doc/files/lib/extensions/object_rb.html +1 -1
  16. data/doc/files/lib/extensions/string_rb.html +1 -1
  17. data/doc/files/lib/extensions/symbol_rb.html +1 -1
  18. data/doc/files/lib/mack_ruby_core_extensions_rb.html +1 -1
  19. data/doc/files/lib/utils/inflections_rb.html +1 -1
  20. data/doc/files/lib/utils/inflector_rb.html +1 -1
  21. data/doc/fr_file_index.html +0 -1
  22. data/lib/extensions/hash.rb +3 -2
  23. data/lib/extensions/kernel.rb +6 -2
  24. data/lib/extensions/object.rb +50 -39
  25. data/lib/mack_ruby_core_extensions.rb +1 -1
  26. data/test/extensions/float_test.rb +2 -0
  27. data/test/extensions/hash_test.rb +23 -7
  28. data/test/extensions/kernel_test.rb +9 -6
  29. data/test/extensions/math_test.rb +20 -5
  30. data/test/extensions/module_test.rb +0 -6
  31. data/test/extensions/nil_test.rb +0 -6
  32. data/test/extensions/object_test.rb +30 -6
  33. data/test/test_helper.rb +41 -0
  34. metadata +2 -6
  35. data/doc/files/lib/extensions/logger_rb.html +0 -101
  36. data/lib/extensions/logger.rb +0 -0
  37. data/test/extensions/logger_test.rb +0 -15
  38. data/test/extensions/method_not_implemented_test.rb +0 -15
@@ -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 12</span>
133
- 12: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">-</span>(<span class="ruby-identifier">ars</span>)
134
- 13: [<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
- 14: <span class="ruby-keyword kw">self</span>
136
- 15: <span class="ruby-keyword kw">end</span>
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
- <span class="ruby-comment cmt"># File lib/extensions/hash.rb, line 3</span>
157
- 3: <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
- 4: <span class="ruby-identifier">a</span> = []
159
- 5: <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
- 6: <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</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
- 7: <span class="ruby-keyword kw">end</span>
162
- 8: <span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">join_string</span>)
163
- 9: <span class="ruby-keyword kw">end</span>
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">&lt;&lt;</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 19</span>
188
- 19: <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
- 20: <span class="ruby-identifier">params</span> = <span class="ruby-value str">''</span>
190
- 21: <span class="ruby-identifier">stack</span> = []
191
- 22:
192
- 23: <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
- 24: <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
- 25: <span class="ruby-identifier">stack</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span>]
195
- 26: <span class="ruby-keyword kw">else</span>
196
- 27: <span class="ruby-identifier">v</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">v</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">escape</span>
197
- 28: <span class="ruby-identifier">params</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{k}=#{v}&amp;&quot;</span>
198
- 29: <span class="ruby-keyword kw">end</span>
199
- 30: <span class="ruby-keyword kw">end</span>
200
- 31:
201
- 32: <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
- 33: <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
- 34: <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
- 35: <span class="ruby-identifier">stack</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-node">&quot;#{parent}[#{k}]&quot;</span>, <span class="ruby-identifier">v</span>]
205
- 36: <span class="ruby-keyword kw">else</span>
206
- 37: <span class="ruby-identifier">v</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">v</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">escape</span>
207
- 38: <span class="ruby-identifier">params</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{parent}[#{k}]=#{v}&amp;&quot;</span>
208
- 39: <span class="ruby-keyword kw">end</span>
209
- 40: <span class="ruby-keyword kw">end</span>
210
- 41: <span class="ruby-keyword kw">end</span>
211
- 42:
212
- 43: <span class="ruby-identifier">params</span>.<span class="ruby-identifier">chop!</span> <span class="ruby-comment cmt"># trailing &amp;</span>
213
- 44: <span class="ruby-identifier">params</span>
214
- 45: <span class="ruby-keyword kw">end</span>
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">&lt;&lt;</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">&lt;&lt;</span> <span class="ruby-node">&quot;#{k}=#{v}&amp;&quot;</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">&lt;&lt;</span> [<span class="ruby-node">&quot;#{parent}[#{k}]&quot;</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">&lt;&lt;</span> <span class="ruby-node">&quot;#{parent}[#{k}]=#{v}&amp;&quot;</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 &amp;</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>
@@ -101,7 +101,7 @@
101
101
 
102
102
  <!-- if method_list -->
103
103
  <div id="methods">
104
- <h3 class="section-bar">Public Class methods</h3>
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-keyword kw">self</span>.<span class="ruby-identifier">pp_to_s</span>(<span class="ruby-identifier">object</span>)
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(&quot;, &quot;)} =&gt; e
158
156
  22: retries -= 1
159
- 23: retry if retries &gt; 0
160
- 24: end
161
- 25: }</span>
162
- 26:
163
- 27: <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">x</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
164
- 28: <span class="ruby-keyword kw">end</span>
157
+ 23: if retries &gt; 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">&amp;</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>
@@ -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 9</span>
134
- 9: <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>)
135
- 10: <span class="ruby-identifier">define_method</span>(<span class="ruby-identifier">meth</span>) <span class="ruby-keyword kw">do</span>
136
- 11: <span class="ruby-identifier">raise</span> <span class="ruby-constant">MethodNotImplemented</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">meth</span>)
137
- 12: <span class="ruby-keyword kw">end</span>
138
- 13: <span class="ruby-keyword kw">end</span>
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(&quot;show&quot;, some_url(:id =&gt; self.id, :foo =&gt; bar, etc... =&gt; 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(&quot;show&quot;, some_url(:id =&gt; self.id, :foo =&gt; bar, etc... =&gt; 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&#8216;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(&quot;foo_var&quot;) do
200
+ link_to(&quot;show&quot;, some_url(:id =&gt; self.id, :foo =&gt; bar, etc... =&gt; 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 75</span>
161
- 75: <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">&amp;</span><span class="ruby-identifier">block</span>)
162
- 76: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
163
- 77: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
164
- 78: <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">&quot;'&quot;</span>)]
165
- 79: <span class="ruby-keyword kw">end</span>
166
- 80: <span class="ruby-identifier">var</span> = <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">&quot;@#{var_name}&quot;</span>)
167
- 81: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">var</span>
168
- 82: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-node">&quot;@#{var_name}&quot;</span>, <span class="ruby-keyword kw">yield</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
169
- 83: <span class="ruby-keyword kw">end</span>
170
- 84: <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">&quot;@#{var_name}&quot;</span>)
171
- 85: <span class="ruby-keyword kw">end</span>
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">&amp;</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">&quot;'&quot;</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">&quot;@#{var_name}&quot;</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">&quot;@#{var_name}&quot;</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">&quot;@#{var_name}&quot;</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
- <span class="ruby-comment cmt"># File lib/extensions/object.rb, line 87</span>
192
- 87: <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">&amp;</span><span class="ruby-identifier">block</span>)
193
- 88: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">var_name</span>.<span class="ruby-identifier">nil?</span>
194
- 89: <span class="ruby-identifier">call</span> = <span class="ruby-identifier">caller</span>[<span class="ruby-value">0</span>]
195
- 90: <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">&quot;'&quot;</span>)]
196
- 91: <span class="ruby-keyword kw">end</span>
197
- 92: <span class="ruby-identifier">remove_instance_variable</span>(<span class="ruby-node">&quot;@#{var_name}&quot;</span>) <span class="ruby-keyword kw">rescue</span>
198
- 93: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
199
- 94: <span class="ruby-keyword kw">end</span>
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">&amp;</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">&quot;'&quot;</span>)]
247
+ 101: <span class="ruby-keyword kw">end</span>
248
+ 102: <span class="ruby-identifier">remove_instance_variable</span>(<span class="ruby-node">&quot;@#{var_name}&quot;</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 # =&gt; [&quot;Animals&quot;, &quot;Dog&quot;]
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 96</span>
220
- 96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">namespaces</span>
221
- 97: <span class="ruby-identifier">ivar_cache</span>(<span class="ruby-value str">&quot;object_namespaces&quot;</span>) <span class="ruby-keyword kw">do</span>
222
- 98: <span class="ruby-identifier">nss</span> = []
223
- 99: <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>
224
- 100: <span class="ruby-identifier">ns</span> = <span class="ruby-identifier">full_name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;::&quot;</span>)
225
- 101: <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
226
- 102: <span class="ruby-identifier">nss</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">n</span>
227
- 103: <span class="ruby-keyword kw">end</span>
228
- 104: <span class="ruby-identifier">nss</span>.<span class="ruby-identifier">pop</span>
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">&quot;object_namespaces&quot;</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">&quot;::&quot;</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&#8230; 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 15</span>
252
- 15: <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">&quot;&quot;</span>, <span class="ruby-identifier">logger</span> = <span class="ruby-keyword kw">nil</span>)
253
- 16: <span class="ruby-identifier">s_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
254
- 17: <span class="ruby-identifier">s</span> = <span class="ruby-node">&quot;---Starting at #{s_time}---&quot;</span>
255
- 18: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">s</span>
256
- 19: <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>
257
- 20: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
258
- 21: <span class="ruby-identifier">e_time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
259
- 22: <span class="ruby-identifier">e</span> = <span class="ruby-node">&quot;---Ending at #{e_time}---&quot;</span>
260
- 23: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>
261
- 24: <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>
262
- 25: <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>
263
- 26: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">secs</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">60</span>
264
- 27: <span class="ruby-identifier">x</span> = <span class="ruby-node">&quot;Running time #{secs} seconds.&quot;</span>
265
- 28: <span class="ruby-keyword kw">else</span>
266
- 29: <span class="ruby-identifier">x</span> = <span class="ruby-node">&quot;Running time roughly #{secs/60} minutes [#{secs} seconds]&quot;</span>
267
- 30: <span class="ruby-keyword kw">end</span>
268
- 31: <span class="ruby-identifier">x</span> <span class="ruby-operator">+=</span> <span class="ruby-node">&quot; [MESSAGE]: #{message}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">message</span>.<span class="ruby-identifier">blank?</span>
269
- 32: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">x</span>
270
- 33: <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>
271
- 34: <span class="ruby-keyword kw">end</span>
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">&quot;&quot;</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">&quot;---Starting at #{s_time}---&quot;</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">&quot;---Ending at #{e_time}---&quot;</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">&lt;</span> <span class="ruby-value">60</span>
327
+ 33: <span class="ruby-identifier">x</span> = <span class="ruby-node">&quot;Running time #{secs} seconds.&quot;</span>
328
+ 34: <span class="ruby-keyword kw">else</span>
329
+ 35: <span class="ruby-identifier">x</span> = <span class="ruby-node">&quot;Running time roughly #{secs/60} minutes [#{secs} seconds]&quot;</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">&quot; [MESSAGE]: #{message}&quot;</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]) # =&gt; 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 36</span>
292
- 36: <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>)
293
- 37: <span class="ruby-identifier">obj</span> = <span class="ruby-keyword kw">self</span>
294
- 38: <span class="ruby-identifier">methods</span> = [<span class="ruby-identifier">methods</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
295
- 39: <span class="ruby-identifier">methods</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>)}
296
- 40: <span class="ruby-identifier">obj</span>
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
- Tue, 25 Mar 2008 17:57:35 -0400
1
+ Wed, 26 Mar 2008 19:20:19 -0400
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 25 17:19:14 -0400 2008</td>
59
+ <td>Tue Mar 25 20:37:52 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 25 17:16:02 -0400 2008</td>
59
+ <td>Tue Mar 25 20:37:52 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 25 17:50:12 -0400 2008</td>
59
+ <td>Tue Mar 25 20:37:52 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>