sugar_refinery 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +157 -0
  3. data/MIT-LICENSE.txt +20 -0
  4. data/README.md +42 -0
  5. data/Rakefile +49 -0
  6. data/doc/create_documentation.rb +471 -0
  7. data/doc/index.html +1687 -0
  8. data/lib/sugar_refinery.rb +1 -0
  9. data/lib/sugar_refinery/alias_for.rb +15 -0
  10. data/lib/sugar_refinery/all.rb +5 -0
  11. data/lib/sugar_refinery/array_op.rb +15 -0
  12. data/lib/sugar_refinery/array_stats.rb +31 -0
  13. data/lib/sugar_refinery/blank.rb +47 -0
  14. data/lib/sugar_refinery/camel_snake.rb +15 -0
  15. data/lib/sugar_refinery/chain_map.rb +11 -0
  16. data/lib/sugar_refinery/constantize.rb +29 -0
  17. data/lib/sugar_refinery/dir_utils.rb +20 -0
  18. data/lib/sugar_refinery/file_force_delete.rb +12 -0
  19. data/lib/sugar_refinery/file_gsub.rb +23 -0
  20. data/lib/sugar_refinery/hash_op.rb +28 -0
  21. data/lib/sugar_refinery/hash_zip.rb +11 -0
  22. data/lib/sugar_refinery/inner_map.rb +15 -0
  23. data/lib/sugar_refinery/lchomp.rb +15 -0
  24. data/lib/sugar_refinery/marshal_copy.rb +11 -0
  25. data/lib/sugar_refinery/mash.rb +22 -0
  26. data/lib/sugar_refinery/ords.rb +17 -0
  27. data/lib/sugar_refinery/regexp_union.rb +17 -0
  28. data/lib/sugar_refinery/same.rb +11 -0
  29. data/lib/sugar_refinery/string_op.rb +20 -0
  30. data/lib/sugar_refinery/version.rb +3 -0
  31. data/spec/alias_for_spec.rb +55 -0
  32. data/spec/array_op_spec.rb +17 -0
  33. data/spec/array_stats_spec.rb +82 -0
  34. data/spec/blank_spec.rb +22 -0
  35. data/spec/camel_snake_spec.rb +15 -0
  36. data/spec/chain_map_spec.rb +16 -0
  37. data/spec/constantize_spec.rb +33 -0
  38. data/spec/dir_utils_spec.rb +32 -0
  39. data/spec/file_force_delete_spec.rb +30 -0
  40. data/spec/file_gsub_spec.rb +26 -0
  41. data/spec/hash_op_spec.rb +28 -0
  42. data/spec/hash_zip_spec.rb +11 -0
  43. data/spec/inner_map_spec.rb +24 -0
  44. data/spec/lchomp_spec.rb +20 -0
  45. data/spec/marshal_copy_spec.rb +15 -0
  46. data/spec/mash_spec.rb +17 -0
  47. data/spec/ords_spec.rb +15 -0
  48. data/spec/regexp_union_spec.rb +19 -0
  49. data/spec/same_spec.rb +10 -0
  50. data/spec/spec_helper.rb +18 -0
  51. data/spec/string_op_spec.rb +22 -0
  52. data/sugar_refinery.gemspec +20 -0
  53. metadata +138 -0
@@ -0,0 +1,1687 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+
8
+ <title>Ruby Sugar Refinery</title>
9
+ <script type="text/javascript">
10
+ var show = function(snippet){
11
+ document.getElementById( snippet ).style.display = 'block'
12
+ if( document.getElementById( 'show_'+snippet ) ){
13
+ document.getElementById( 'show_'+snippet ).style.display = 'none'
14
+ }
15
+ }
16
+ </script>
17
+ <style type="text/css">
18
+ body{
19
+ background-color:#aaa;
20
+ color:#111;
21
+ font-family:sans-serif;
22
+ }
23
+
24
+ #world{
25
+ background:#fff;
26
+ }
27
+
28
+ h1, h2, h3, h4, h5, h6{
29
+ margin:0px;
30
+ padding:0px;
31
+ }
32
+
33
+ h1{
34
+ color:#222;
35
+ text-align:left;
36
+ padding:0.7em;
37
+ }
38
+ h2{
39
+ margin-left:1em;
40
+ margin-top:0.8em;
41
+ margin-bottom:0.5em;
42
+ }
43
+
44
+ th{
45
+ width:200px;
46
+ color:#444;
47
+ }
48
+
49
+ p{
50
+ margin:0px;
51
+ margin-bottom:0.5em;
52
+ }
53
+
54
+ p.text{
55
+ margin-left:1.5em;
56
+ margin-right:1em;
57
+ }
58
+
59
+ code{
60
+ }
61
+
62
+ .scode{
63
+ display:block;
64
+ margin:0.8em;
65
+ margin-left:0;
66
+ padding:0.5em;
67
+ border:1px solid black;
68
+ background:#eee;
69
+ }
70
+
71
+ .cubes{
72
+ margin:0px;
73
+ margin-left:1.65em;
74
+ margin-right:1em;
75
+ }
76
+
77
+ a{
78
+ color:#111;
79
+ }
80
+
81
+ table{
82
+ margin:0.8em;
83
+ margin-top:0.2em;
84
+ margin-left:0;
85
+ padding:0.2em;
86
+ border:1px solid #111;
87
+ background:#eee;
88
+ overflow:auto;
89
+ display:block;
90
+ }
91
+
92
+ ul{
93
+ margin:5px 0px !important;
94
+ padding:none;
95
+ }
96
+
97
+ th{
98
+ text-align:left;
99
+ vertical-align:top;
100
+ padding-right:3em;
101
+ }
102
+
103
+ td{
104
+ width:100%;
105
+ }
106
+
107
+ li{
108
+ list-style:none;
109
+ }
110
+
111
+
112
+ #foot{
113
+ text-align:left;
114
+ padding:0.3em;
115
+ font-size:70%
116
+ }
117
+ #foot, #foot a{
118
+ color:#444;
119
+ }
120
+ #smile{
121
+ font-size:150%;
122
+ float:right;
123
+ }
124
+ #smile a{
125
+ text-decoration:none;
126
+ }
127
+
128
+ .small{
129
+ font-size:70%;
130
+ }
131
+
132
+ code, pre{
133
+ font-face:mono;
134
+ margin:0px;
135
+ padding:0px;
136
+ }
137
+
138
+ .source{
139
+ display:none;
140
+ width:98%;
141
+ padding: 3px 5px;
142
+ overflow: auto;
143
+ font-size: 12px;
144
+ background-color: #f8f8f8;
145
+ border:1px solid #005;
146
+ border: 1px solid silver;
147
+ font-family: 'Courier New', 'Terminal', monospace;
148
+ color: #000;
149
+ }
150
+
151
+ # http://coderay.rubychan.de/
152
+ .source pre { margin: 0px; }
153
+
154
+ span.source { white-space: pre; border: 0px; padding: 2px; }
155
+
156
+ table.source { border-collapse: collapse; width: 100%; padding: 2px; }
157
+ table.source td { padding: 2px 4px; vertical-align: top; }
158
+
159
+ .source .line_numbers, .source .no {
160
+ background-color: #def;
161
+ color: gray;
162
+ text-align: right;
163
+ }
164
+ .source .line_numbers a:target, .source .no a:target { color: blue; }
165
+ .source .line_numbers .highlighted, .source .no .highlighted { color: red; }
166
+ .source .no { padding: 0px 4px; }
167
+ .source .code { width: 100%; }
168
+ .source .code pre { overflow: auto; }
169
+
170
+ .source .debug { color:white ! important; background:blue ! important; }
171
+
172
+ .source .an { color:#007 }
173
+ .source .at { color:#f08 }
174
+ .source .av { color:#700 }
175
+ .source .bi { color:#509; font-weight:bold }
176
+ .source .c { color:#888; }
177
+ .source .c .dl { color:#444; }
178
+ .source .c .ch { color:#444; }
179
+
180
+ .source .ch { color:#04D }
181
+ .source .ch .k { color:#04D }
182
+ .source .ch .dl { color:#039 }
183
+
184
+ .source .cl { color:#B06; font-weight:bold }
185
+ .source .cm { color:#A08; font-weight:bold }
186
+ .source .co { color:#036; font-weight:bold }
187
+ .source .cr { color:#0A0 }
188
+ .source .cv { color:#369 }
189
+ .source .de { color:#B0B; }
190
+ .source .df { color:#099; font-weight:bold }
191
+ .source .di { color:#088; font-weight:bold }
192
+ .source .dl { color:black }
193
+ .source .do { color:#970 }
194
+ .source .dt { color:#34b }
195
+ .source .ds { color:#D42; font-weight:bold }
196
+ .source .e { color:#666; font-weight:bold }
197
+ .source .en { color:#800; font-weight:bold }
198
+ .source .er { color:#F00; background-color:#FAA }
199
+ .source .ex { color:#C00; font-weight:bold }
200
+ .source .fl { color:#60E; font-weight:bold }
201
+ .source .fu { color:#06B; font-weight:bold }
202
+ .source .gv { color:#d70; font-weight:bold }
203
+ .source .hx { color:#058; font-weight:bold }
204
+ .source .i { color:#00D; font-weight:bold }
205
+ .source .ic { color:#B44; font-weight:bold }
206
+
207
+ .source .il { background-color: hsla(0,0%,0%,0.1); color: black }
208
+ .source .il .idl { font-weight: bold; color: #666 }
209
+ .source .idl { font-weight: bold; background-color: hsla(0,0%,0%,0.1); color: #666; }
210
+
211
+ .source .im { color:#f00; }
212
+ .source .in { color:#B2B; font-weight:bold }
213
+ .source .iv { color:#33B }
214
+ .source .la { color:#970; font-weight:bold }
215
+ .source .lv { color:#963 }
216
+ .source .ns { color:#707; font-weight:bold }
217
+ .source .oc { color:#40E; font-weight:bold }
218
+ .source .op { }
219
+ .source .pc { color:#058; font-weight:bold }
220
+ .source .pd { color:#369; font-weight:bold }
221
+ .source .pp { color:#579; }
222
+ .source .ps { color:#00C; font-weight:bold }
223
+ .source .pt { color:#074; font-weight:bold }
224
+ .source .r, .kw { color:#080; font-weight:bold }
225
+
226
+ .source .ke { color: #808; }
227
+ .source .ke .dl { color: #606; }
228
+ .source .ke .ch { color: #80f; }
229
+ .source .vl { color: #088; }
230
+
231
+ .source .rx { background-color:hsla(300,100%,50%,0.1); }
232
+ .source .rx .k { color:#808 }
233
+ .source .rx .dl { color:#404 }
234
+ .source .rx .mod { color:#C2C }
235
+ .source .rx .fu { color:#404; font-weight: bold }
236
+
237
+ .source .s { background-color:hsla(0,100%,50%,0.1); }
238
+ .source .s .k { color: #D20; }
239
+ .source .s .ch { color: #b0b; }
240
+ .source .s .dl { color: #710; }
241
+
242
+ .source .sh { background-color:hsla(120,100%,50%,0.1); }
243
+ .source .sh .k { color:#2B2 }
244
+ .source .sh .dl { color:#161 }
245
+
246
+ .source .sy { color:#A60 }
247
+ .source .sy .k { color:#A60 }
248
+ .source .sy .dl { color:#630 }
249
+
250
+ .source .ta { color:#070 }
251
+ .source .ts { color:#D70; font-weight:bold }
252
+ .source .ty { color:#339; font-weight:bold }
253
+ .source .v { color:#036 }
254
+ .source .xt { color:#444 }
255
+
256
+ .source .ins { background: hsla(120,100%,50%,0.2) }
257
+ .source .del { background: hsla(0,100%,50%,0.2) }
258
+ .source .chg { color: #aaf; background: #007; }
259
+ .source .head { color: #f8f; background: #505 }
260
+ .source .head .filename { color: white; }
261
+
262
+ .source .ins .eye { background-color: hsla(120,100%,50%,0.2) }
263
+ .source .del .eye { background-color: hsla(0,100%,50%,0.2) }
264
+
265
+ .source .ins .ins { color: #080; background:transparent; font-weight:bold }
266
+ .source .del .del { color: #800; background:transparent; font-weight:bold }
267
+ .source .chg .chg { color: #66f; }
268
+ .source .head .head { color: #f4f; }
269
+
270
+ .rubylogo{
271
+ margin-left:1.4em;
272
+ margin-top:0.6em;
273
+ margin-right:1em;
274
+ float:left;
275
+ }
276
+
277
+ </style>
278
+ </head>
279
+ <body>
280
+ <div id="world">
281
+ <img class="rubylogo" alt="ruby" src="data:image/png;base64,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" />
282
+ <h1>Ruby Sugar Refinery</h1>
283
+ <br/>
284
+ <p class="text">The Ruby Sugar Refinery is a collection of tiny <a href="http://ruby-doc.org/core-2.3.0/doc/syntax/refinements_rdoc.html">refinements</a> (declarative local core extensions) for Ruby.</p>
285
+
286
+ <h2>Setup &amp; Usage</h2>
287
+ <p class="text">
288
+ Add to Gemfile:
289
+ </p>
290
+
291
+ <div class="cubes">
292
+ <code class="scode">gem 'sugar_refinery', require: 'sugar_refinery/all'</code>
293
+ </div>
294
+
295
+ <p class="text">
296
+ Then add refinements to the current Ruby file or module:
297
+ <div class="cubes">
298
+ <pre class="scode">using SugarRefinery::CamelSnake
299
+ using SugarRefinery::HashZip
300
+
301
+ "ClassName".to_snake # => "class_name"
302
+ Hash.zip [1,2,3], [4,5,6] # => {1=>4, 2=>5, 3=>6}</pre>
303
+ </div>
304
+ </p>
305
+
306
+ <h2>List of Refinements</h2>
307
+
308
+ <div class="cubes"><h3 title="require 'sugar_refinery/alias_for'" id="alias_for">alias_for</h3>
309
+ <table class="cube_table"
310
+ id="alias_for_cube"
311
+ title="require 'sugar_refinery/alias_for'"> <tr><th>Summary</th> <td>A different way to create aliases: Reversed order and you can pass multiple alias names. The order feels more logical</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
312
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">AliasFor</span></pre></div>
313
+ </div>
314
+ </div></td></tr><tr><th>Usage</th> <td><h5>Module#alias_for, Module#aliases_for</h5><div class="usage source" style="display:block"><div class="CodeRay">
315
+ <div class="code"><pre><span style="color:#777"># creates an alias for the method :methods with the name ms</span>
316
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
317
+ alias_for <span style="color:#A60">:methods</span>, <span style="color:#A60">:ms</span>
318
+ <span style="color:#080;font-weight:bold">end</span>
319
+
320
+ <span style="color:#777"># creates multiple aliases</span>
321
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Enumerable</span>
322
+ aliases_for <span style="color:#A60">:zip</span>, <span style="color:#A60">:with</span>, <span style="color:#A60">:%</span>
323
+ <span style="color:#080;font-weight:bold">end</span>
324
+ </pre></div>
325
+ </div>
326
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_alias_for_spec">(<a href="javascript:show('alias_for_spec')">show</a>)</span>
327
+ <div class="source" id="alias_for_spec"><div class="CodeRay">
328
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/alias_for</span><span style="color:#710">'</span></span>
329
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">AliasFor</span>
330
+
331
+
332
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">alias_for</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
333
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should create an alias for instance methods</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
334
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Array</span>
335
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m2</span>
336
+ <span style="color:#00D">2</span>
337
+ <span style="color:#080;font-weight:bold">end</span>
338
+ aliases_for <span style="color:#A60">:m2</span>, <span style="color:#A60">:a2</span>, <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#740">'</span><span style="color:#A60">a-2</span><span style="color:#740">'</span></span>
339
+ <span style="color:#080;font-weight:bold">end</span>
340
+ proc <span style="color:#080;font-weight:bold">do</span>
341
+ [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>].a2.should == <span style="color:#00D">2</span>
342
+ [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>].send(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a-2</span><span style="color:#710">'</span></span>).should == <span style="color:#00D">2</span>
343
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
344
+ <span style="color:#080;font-weight:bold">end</span>
345
+
346
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should create an alias for class (singleton) methods</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
347
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Array</span>
348
+ <span style="color:#080;font-weight:bold">class</span> &lt;&lt; <span style="color:#B06;font-weight:bold">Array</span>
349
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m3</span>
350
+ <span style="color:#00D">3</span>
351
+ <span style="color:#080;font-weight:bold">end</span>
352
+ alias_for <span style="color:#A60">:m3</span>, <span style="color:#A60">:a3</span>
353
+ <span style="color:#080;font-weight:bold">end</span>
354
+ <span style="color:#080;font-weight:bold">end</span>
355
+
356
+ proc{
357
+ <span style="color:#036;font-weight:bold">Array</span>.a3.should == <span style="color:#00D">3</span>
358
+ }.should_not raise_exception
359
+ <span style="color:#080;font-weight:bold">end</span>
360
+
361
+
362
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should create aliases for the first argument with all other arguments</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
363
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
364
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m4</span>
365
+ <span style="color:#00D">4</span>
366
+ <span style="color:#080;font-weight:bold">end</span>
367
+ alias_for <span style="color:#A60">:m4</span>, <span style="color:#A60">:ma</span>, <span style="color:#A60">:mb</span>, <span style="color:#A60">:mc</span>
368
+ <span style="color:#080;font-weight:bold">end</span>
369
+
370
+ proc{
371
+ <span style="color:#00D">1</span>.ma.should == <span style="color:#00D">4</span>
372
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">1</span><span style="color:#710">&quot;</span></span>.mb.should == <span style="color:#00D">4</span>
373
+ [<span style="color:#00D">1</span>].mc.should == <span style="color:#00D">4</span>
374
+ }.should_not raise_exception
375
+ <span style="color:#080;font-weight:bold">end</span>
376
+
377
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">works with uncommon chars</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
378
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
379
+ alias_for <span style="color:#A60">:tainted?</span>, <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#740">&quot;</span><span style="color:#A60">tain-ted?</span><span style="color:#740">&quot;</span></span>
380
+ <span style="color:#080;font-weight:bold">end</span>
381
+ <span style="color:#080;font-weight:bold">end</span>
382
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
383
+ </div>
384
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_alias_for_source">(<a href="javascript:show('alias_for_source')">show</a>)</span>
385
+ <div class="source" id="alias_for_source"><div class="CodeRay">
386
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
387
+
388
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
389
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">AliasFor</span>
390
+ refine <span style="color:#036;font-weight:bold">Module</span> <span style="color:#080;font-weight:bold">do</span>
391
+ private
392
+
393
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">alias_for</span>(m, *aliases)
394
+ aliases.each{ |a| class_eval <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">alias :'</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span> a <span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">' :'</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span> m <span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">'</span><span style="color:#710">&quot;</span></span> }
395
+ <span style="color:#080;font-weight:bold">end</span>
396
+
397
+ <span style="color:#080;font-weight:bold">alias</span> <span style="color:#06B;font-weight:bold">aliases_for</span> <span style="color:#06B;font-weight:bold">alias_for</span>
398
+ <span style="color:#080;font-weight:bold">end</span>
399
+ <span style="color:#080;font-weight:bold">end</span>
400
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
401
+ </div>
402
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/array_op'" id="array_op">array_op</h3>
403
+ <table class="cube_table"
404
+ id="array_op_cube"
405
+ title="require 'sugar_refinery/array_op'"> <tr><th>Summary</th> <td>Operators one could miss for <code>Array</code></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
406
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ArrayOp</span></pre></div>
407
+ </div>
408
+ </div></td></tr><tr><th>Usage</th> <td><h5>Array#^</h5><div class="usage source" style="display:block"><div class="CodeRay">
409
+ <div class="code"><pre>[<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>,<span style="color:#00D">4</span>] ^ [<span style="color:#00D">3</span>,<span style="color:#00D">4</span>,<span style="color:#00D">5</span>,<span style="color:#00D">6</span>] <span style="color:#777"># =&gt; [1,2,5,6]</span></pre></div>
410
+ </div>
411
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_array_op_spec">(<a href="javascript:show('array_op_spec')">show</a>)</span>
412
+ <div class="source" id="array_op_spec"><div class="CodeRay">
413
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/array_op</span><span style="color:#710">'</span></span>
414
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ArrayOp</span>
415
+
416
+
417
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Array#^</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
418
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">does an exclusive or</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
419
+ a = [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>,<span style="color:#00D">4</span>]
420
+ b = [<span style="color:#00D">3</span>,<span style="color:#00D">4</span>,<span style="color:#00D">5</span>,<span style="color:#00D">6</span>]
421
+ (a^b).should == [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">5</span>,<span style="color:#00D">6</span>]
422
+ <span style="color:#080;font-weight:bold">end</span>
423
+ <span style="color:#080;font-weight:bold">end</span>
424
+
425
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Array#**</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
426
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">returns the array product</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
427
+ ([<span style="color:#00D">1</span>,<span style="color:#00D">2</span>] ** <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w[</span><span style="color:#D20">a b</span><span style="color:#710">]</span></span>).should == [[<span style="color:#00D">1</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">a</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D">1</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">b</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D">2</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">a</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D">2</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">b</span><span style="color:#710">&quot;</span></span>]]
428
+ <span style="color:#080;font-weight:bold">end</span>
429
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
430
+ </div>
431
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_array_op_source">(<a href="javascript:show('array_op_source')">show</a>)</span>
432
+ <div class="source" id="array_op_source"><div class="CodeRay">
433
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
434
+
435
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
436
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">ArrayOp</span>
437
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
438
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">^</span>(other)
439
+ (<span style="color:#069">self</span> - other) + (other - <span style="color:#069">self</span>)
440
+ <span style="color:#080;font-weight:bold">end</span>
441
+
442
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">**</span>(*o, &amp;block)
443
+ product *o, &amp;block
444
+ <span style="color:#080;font-weight:bold">end</span>
445
+ <span style="color:#080;font-weight:bold">end</span>
446
+ <span style="color:#080;font-weight:bold">end</span>
447
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
448
+ </div>
449
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/array_stats'" id="array_stats">array_stats</h3>
450
+ <table class="cube_table"
451
+ id="array_stats_cube"
452
+ title="require 'sugar_refinery/array_stats'"> <tr><th>Summary</th> <td>Statistics for <code>Array</code></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
453
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ArrayStats</span></pre></div>
454
+ </div>
455
+ </div></td></tr><tr><th>Usage</th> <td><h5>Array#mean</h5><div class="usage source" style="display:block"><div class="CodeRay">
456
+ <div class="code"><pre><span style="color:#777"># calculates mean (average)</span></pre></div>
457
+ </div>
458
+ </div><h5>Array#stdev</h5><div class="usage source" style="display:block"><div class="CodeRay">
459
+ <div class="code"><pre><span style="color:#777"># calculates standard deviation (takes :sample or :population as argument)</span></pre></div>
460
+ </div>
461
+ </div><h5>Array#stdev_sample</h5><div class="usage source" style="display:block"><div class="CodeRay">
462
+ <div class="code"><pre><span style="color:#777"># calculates sample standard deviation</span></pre></div>
463
+ </div>
464
+ </div><h5>Array#stdev_population</h5><div class="usage source" style="display:block"><div class="CodeRay">
465
+ <div class="code"><pre><span style="color:#777"># calculates population standard deviation</span></pre></div>
466
+ </div>
467
+ </div><h5>Array#z_score</h5><div class="usage source" style="display:block"><div class="CodeRay">
468
+ <div class="code"><pre><span style="color:#777"># calculates standard score</span></pre></div>
469
+ </div>
470
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_array_stats_spec">(<a href="javascript:show('array_stats_spec')">show</a>)</span>
471
+ <div class="source" id="array_stats_spec"><div class="CodeRay">
472
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">sugar_refinery/array_stats</span><span style="color:#710">&quot;</span></span>
473
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ArrayStats</span>
474
+
475
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">doing statistics on arrays</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
476
+ let(<span style="color:#A60">:list</span>) { (<span style="color:#00D">2</span>..<span style="color:#00D">5</span>).to_a }
477
+
478
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#mean</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
479
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should return the average</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
480
+ list.mean.should == <span style="color:#60E">3.5</span>
481
+ <span style="color:#080;font-weight:bold">end</span>
482
+ <span style="color:#080;font-weight:bold">end</span>
483
+
484
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#stdev_sample</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
485
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should return the standard deviation of the sample</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
486
+ list.stdev_sample.should be_close(<span style="color:#60E">1.2909944487358056</span>, <span style="color:#60E">1e-8</span>)
487
+ <span style="color:#080;font-weight:bold">end</span>
488
+ <span style="color:#080;font-weight:bold">end</span>
489
+
490
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#stdev_population</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
491
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should return the standard deviation of the population</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
492
+ list.stdev_population.should be_close(<span style="color:#60E">1.118033988749895</span>, <span style="color:#60E">1e-8</span>)
493
+ <span style="color:#080;font-weight:bold">end</span>
494
+ <span style="color:#080;font-weight:bold">end</span>
495
+
496
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#stdev</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
497
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should default to population</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
498
+ list.stdev.should be_close(list.stdev_population, <span style="color:#60E">1e-8</span>)
499
+ <span style="color:#080;font-weight:bold">end</span>
500
+
501
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate sample correctly</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
502
+ list.stdev(<span style="color:#A60">:sample</span>).should be_close(list.stdev_sample, <span style="color:#60E">1e-8</span>)
503
+ <span style="color:#080;font-weight:bold">end</span>
504
+
505
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate population correctly</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
506
+ list.stdev(<span style="color:#A60">:population</span>).should be_close(list.stdev_population, <span style="color:#60E">1e-8</span>)
507
+ <span style="color:#080;font-weight:bold">end</span>
508
+
509
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should raise an error with any other key</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
510
+ expect { list.stdev(<span style="color:#A60">:pony</span>) }.to raise_error(<span style="color:#036;font-weight:bold">ArgumentError</span>)
511
+ <span style="color:#080;font-weight:bold">end</span>
512
+ <span style="color:#080;font-weight:bold">end</span>
513
+
514
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#z_score</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
515
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should default to population</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
516
+ list.z_score.zip(list.z_score(<span style="color:#A60">:population</span>)).each <span style="color:#080;font-weight:bold">do</span> |value, actual|
517
+ value.should be_close(actual, <span style="color:#60E">1e-8</span>)
518
+ <span style="color:#080;font-weight:bold">end</span>
519
+ <span style="color:#080;font-weight:bold">end</span>
520
+
521
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate sample correctly</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
522
+ sample_z_score = [
523
+ <span style="color:#60E">-1.161895003862225</span>,
524
+ <span style="color:#60E">-0.3872983346207417</span>,
525
+ <span style="color:#60E">0.3872983346207417</span>,
526
+ <span style="color:#60E">1.161895003862225</span>
527
+ ]
528
+
529
+ p list
530
+
531
+ list.z_score(<span style="color:#A60">:sample</span>).zip(sample_z_score).each <span style="color:#080;font-weight:bold">do</span> |value, actual|
532
+ value.should be_close(actual, <span style="color:#60E">1e-8</span>)
533
+ <span style="color:#080;font-weight:bold">end</span>
534
+ <span style="color:#080;font-weight:bold">end</span>
535
+
536
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate population correctly</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
537
+ population_z_score = [
538
+ <span style="color:#60E">-1.3416407864998738</span>,
539
+ <span style="color:#60E">-0.4472135954999579</span>,
540
+ <span style="color:#60E">0.4472135954999579</span>,
541
+ <span style="color:#60E">1.3416407864998738</span>
542
+ ]
543
+
544
+ list.z_score(<span style="color:#A60">:population</span>).zip(population_z_score).each <span style="color:#080;font-weight:bold">do</span> |value, actual|
545
+ value.should be_close(actual, <span style="color:#60E">1e-8</span>)
546
+ <span style="color:#080;font-weight:bold">end</span>
547
+ <span style="color:#080;font-weight:bold">end</span>
548
+
549
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should raise an error with any other key</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
550
+ expect { list.z_score(<span style="color:#A60">:pony</span>) }.to raise_error(<span style="color:#036;font-weight:bold">ArgumentError</span>)
551
+ <span style="color:#080;font-weight:bold">end</span>
552
+ <span style="color:#080;font-weight:bold">end</span>
553
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
554
+ </div>
555
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_array_stats_source">(<a href="javascript:show('array_stats_source')">show</a>)</span>
556
+ <div class="source" id="array_stats_source"><div class="CodeRay">
557
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
558
+
559
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
560
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">ArrayStats</span>
561
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
562
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">mean</span>
563
+ inject(&amp;<span style="color:#A60">:+</span>) / length.to_f
564
+ <span style="color:#080;font-weight:bold">end</span>
565
+
566
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">stdev</span>(type = <span style="color:#A60">:population</span>)
567
+ <span style="color:#080;font-weight:bold">case</span> type
568
+ <span style="color:#080;font-weight:bold">when</span> <span style="color:#A60">:population</span> <span style="color:#080;font-weight:bold">then</span> stdev_population
569
+ <span style="color:#080;font-weight:bold">when</span> <span style="color:#A60">:sample</span> <span style="color:#080;font-weight:bold">then</span> stdev_sample
570
+ <span style="color:#080;font-weight:bold">else</span> raise <span style="color:#036;font-weight:bold">ArgumentError</span>.new(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">%s is not a valid argument</span><span style="color:#710">&quot;</span></span> % type)
571
+ <span style="color:#080;font-weight:bold">end</span>
572
+ <span style="color:#080;font-weight:bold">end</span>
573
+
574
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">stdev_sample</span>
575
+ <span style="color:#036;font-weight:bold">Math</span>.sqrt(inject(<span style="color:#60E">0.0</span>) { |sum, x| sum + (mean - x) ** <span style="color:#00D">2</span> } / (length - <span style="color:#00D">1</span>))
576
+ <span style="color:#080;font-weight:bold">end</span>
577
+
578
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">stdev_population</span>
579
+ <span style="color:#036;font-weight:bold">Math</span>.sqrt(inject(<span style="color:#60E">0.0</span>) { |sum, x| sum + (mean - x) ** <span style="color:#00D">2</span> } / length)
580
+ <span style="color:#080;font-weight:bold">end</span>
581
+
582
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">z_score</span>(type = <span style="color:#A60">:population</span>)
583
+ map { |x| (x - mean) / stdev(type) }
584
+ <span style="color:#080;font-weight:bold">end</span>
585
+ <span style="color:#080;font-weight:bold">end</span>
586
+ <span style="color:#080;font-weight:bold">end</span>
587
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
588
+ </div>
589
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/blank'" id="blank">blank</h3>
590
+ <table class="cube_table"
591
+ id="blank_cube"
592
+ title="require 'sugar_refinery/blank'"> <tr><th>Summary</th> <td>Does pretty the same as in ActiveSupport: Every object can be asked if it is blank or present</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
593
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Blank</span></pre></div>
594
+ </div>
595
+ </div></td></tr><tr><th>Usage</th> <td><h5>Object#blank?</h5><div class="usage source" style="display:block"><div class="CodeRay">
596
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">an object</span><span style="color:#710">'</span></span>.blank? <span style="color:#777"># =&gt; false</span>
597
+ <span style="color:#069">nil</span>.present? <span style="color:#777"># =&gt; false</span>
598
+ </pre></div>
599
+ </div>
600
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_blank_spec">(<a href="javascript:show('blank_spec')">show</a>)</span>
601
+ <div class="source" id="blank_spec"><div class="CodeRay">
602
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/blank</span><span style="color:#710">'</span></span>
603
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Blank</span>
604
+
605
+
606
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Object#blank?</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
607
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should be blank for blank values</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
608
+ blank_values = [ <span style="color:#069">nil</span>, <span style="color:#069">false</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20"> </span><span style="color:#710">'</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20"> </span><span style="color:#b0b">\n</span><span style="color:#b0b">\t</span><span style="color:#D20"> </span><span style="color:#b0b">\r</span><span style="color:#D20"> </span><span style="color:#710">&quot;</span></span>, [], {}, <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#404">/</span></span> ]
609
+
610
+ blank_values.each{ |blank|
611
+ blank.blank?.should == <span style="color:#069">true</span>
612
+ }
613
+ <span style="color:#080;font-weight:bold">end</span>
614
+
615
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should not be blank for non blank values</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
616
+ present_values = [ <span style="color:#036;font-weight:bold">Object</span>.new, <span style="color:#069">true</span>, <span style="color:#00D">0</span>, <span style="color:#00D">1</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a</span><span style="color:#710">'</span></span>, [<span style="color:#069">nil</span>], { <span style="color:#069">nil</span> =&gt; <span style="color:#069">nil</span> } ]
617
+
618
+ present_values.each{ |present|
619
+ present.blank?.should == <span style="color:#069">false</span>
620
+ }
621
+ <span style="color:#080;font-weight:bold">end</span>
622
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
623
+ </div>
624
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_blank_source">(<a href="javascript:show('blank_source')">show</a>)</span>
625
+ <div class="source" id="blank_source"><div class="CodeRay">
626
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
627
+
628
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
629
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Blank</span>
630
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
631
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>
632
+ <span style="color:#080;font-weight:bold">if</span> respond_to? <span style="color:#A60">:empty?</span> <span style="color:#080;font-weight:bold">then</span> empty? <span style="color:#080;font-weight:bold">else</span> !<span style="color:#069">self</span> <span style="color:#080;font-weight:bold">end</span>
633
+ <span style="color:#080;font-weight:bold">end</span>
634
+
635
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">present?</span>
636
+ !blank?
637
+ <span style="color:#080;font-weight:bold">end</span>
638
+ <span style="color:#080;font-weight:bold">end</span>
639
+
640
+ refine <span style="color:#036;font-weight:bold">NilClass</span> <span style="color:#080;font-weight:bold">do</span>
641
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">true</span> <span style="color:#080;font-weight:bold">end</span>
642
+ <span style="color:#080;font-weight:bold">end</span>
643
+
644
+ refine <span style="color:#036;font-weight:bold">FalseClass</span> <span style="color:#080;font-weight:bold">do</span>
645
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">true</span> <span style="color:#080;font-weight:bold">end</span>
646
+ <span style="color:#080;font-weight:bold">end</span>
647
+
648
+ refine <span style="color:#036;font-weight:bold">TrueClass</span> <span style="color:#080;font-weight:bold">do</span>
649
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">false</span> <span style="color:#080;font-weight:bold">end</span>
650
+ <span style="color:#080;font-weight:bold">end</span>
651
+
652
+ refine <span style="color:#036;font-weight:bold">Numeric</span> <span style="color:#080;font-weight:bold">do</span>
653
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">false</span> <span style="color:#080;font-weight:bold">end</span>
654
+ <span style="color:#080;font-weight:bold">end</span>
655
+
656
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
657
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() empty? <span style="color:#080;font-weight:bold">end</span>
658
+ <span style="color:#080;font-weight:bold">end</span>
659
+
660
+ refine <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
661
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() empty? <span style="color:#080;font-weight:bold">end</span>
662
+ <span style="color:#080;font-weight:bold">end</span>
663
+
664
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
665
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">self</span> !~ <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#D20">\S</span><span style="color:#404">/</span></span> <span style="color:#080;font-weight:bold">end</span>
666
+ <span style="color:#080;font-weight:bold">end</span>
667
+
668
+ refine <span style="color:#036;font-weight:bold">Regexp</span> <span style="color:#080;font-weight:bold">do</span>
669
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#069">self</span> == <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#404">/</span></span> <span style="color:#080;font-weight:bold">end</span>
670
+ <span style="color:#080;font-weight:bold">end</span>
671
+ <span style="color:#080;font-weight:bold">end</span>
672
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
673
+ </div>
674
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/camel_snake'" id="camel_snake">camel_snake</h3>
675
+ <table class="cube_table"
676
+ id="camel_snake_cube"
677
+ title="require 'sugar_refinery/camel_snake'"> <tr><th>Summary</th> <td>Provides <code>String#to_camel</code> and <code>String#to_snake</code>.</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
678
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">CamelSnake</span></pre></div>
679
+ </div>
680
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#to_camel</h5><div class="usage source" style="display:block"><div class="CodeRay">
681
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">was_snake_string</span><span style="color:#710">'</span></span>.to_camel <span style="color:#777"># =&gt; 'WasSnakeString'</span></pre></div>
682
+ </div>
683
+ </div><h5>String#to_snake</h5><div class="usage source" style="display:block"><div class="CodeRay">
684
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">WasCamelString</span><span style="color:#710">'</span></span>.to_snake <span style="color:#777"># =&gt; 'was_camel_string'</span></pre></div>
685
+ </div>
686
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_camel_snake_spec">(<a href="javascript:show('camel_snake_spec')">show</a>)</span>
687
+ <div class="source" id="camel_snake_spec"><div class="CodeRay">
688
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/camel_snake</span><span style="color:#710">'</span></span>
689
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">CamelSnake</span>
690
+
691
+
692
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#to_camel</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
693
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should turn a snake_cased string to CamelCase</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
694
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">was_snake_case</span><span style="color:#710">'</span></span>.to_camel.should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">WasSnakeCase</span><span style="color:#710">'</span></span>
695
+ <span style="color:#080;font-weight:bold">end</span>
696
+ <span style="color:#080;font-weight:bold">end</span>
697
+
698
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#to_snake</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
699
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should turn a CamelCased string to snake_case</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
700
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">WasCamelCase</span><span style="color:#710">'</span></span>.to_snake.should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">was_camel_case</span><span style="color:#710">'</span></span>
701
+ <span style="color:#080;font-weight:bold">end</span>
702
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
703
+ </div>
704
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_camel_snake_source">(<a href="javascript:show('camel_snake_source')">show</a>)</span>
705
+ <div class="source" id="camel_snake_source"><div class="CodeRay">
706
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
707
+
708
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
709
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">CamelSnake</span>
710
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
711
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">to_snake</span>
712
+ gsub(<span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">(?&lt;!^)[A-Z]</span><span style="color:#404">/</span></span>) <span style="color:#080;font-weight:bold">do</span> <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">_</span><span style="color:#666">#</span><span style="color:#d70">$&amp;</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">end</span>.downcase
713
+ <span style="color:#080;font-weight:bold">end</span>
714
+
715
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">to_camel</span>
716
+ gsub(<span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">(?:^|_)([a-z])</span><span style="color:#404">/</span></span>) <span style="color:#080;font-weight:bold">do</span> <span style="color:#d70">$1</span>.upcase <span style="color:#080;font-weight:bold">end</span>
717
+ <span style="color:#080;font-weight:bold">end</span>
718
+ <span style="color:#080;font-weight:bold">end</span>
719
+ <span style="color:#080;font-weight:bold">end</span>
720
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
721
+ </div>
722
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/chain_map'" id="chain_map">chain_map</h3>
723
+ <table class="cube_table"
724
+ id="chain_map_cube"
725
+ title="require 'sugar_refinery/chain_map'"> <tr><th>Summary</th> <td>Chain multiple procs on <code>Array</code> elements</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
726
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ChainMap</span></pre></div>
727
+ </div>
728
+ </div></td></tr><tr><th>Usage</th> <td><h5>Array#chain_map</h5><div class="usage source" style="display:block"><div class="CodeRay">
729
+ <div class="code"><pre>[<span style="color:#00D">-3</span>, <span style="color:#00D">-2</span>, <span style="color:#00D">-1</span>].chain_map(<span style="color:#A60">:abs</span>, <span style="color:#A60">:to_s</span>) <span style="color:#777"># =&gt; [&quot;3&quot;, &quot;2&quot;, &quot;1&quot;]</span></pre></div>
730
+ </div>
731
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_chain_map_spec">(<a href="javascript:show('chain_map_spec')">show</a>)</span>
732
+ <div class="source" id="chain_map_spec"><div class="CodeRay">
733
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">sugar_refinery/chain_map</span><span style="color:#710">&quot;</span></span>
734
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">ChainMap</span>
735
+
736
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#chain_map</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
737
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should repeatedly chain symbols as map calls</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
738
+ list = [<span style="color:#00D">-3</span>, <span style="color:#00D">-2</span>, <span style="color:#00D">-1</span>]
739
+
740
+ list.chain_map(<span style="color:#A60">:abs</span>, <span style="color:#A60">:to_s</span>) == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w{</span><span style="color:#D20">3 2 1</span><span style="color:#710">}</span></span>
741
+ <span style="color:#080;font-weight:bold">end</span>
742
+
743
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should repeatedly chain blocks as map calls</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
744
+ list = [<span style="color:#00D">-3</span>, <span style="color:#00D">-2</span>, <span style="color:#00D">-1</span>]
745
+
746
+ list.chain_map(-&gt;(e) { e ** <span style="color:#00D">2</span> }, -&gt;(e) { e * <span style="color:#00D">-1</span> }) == [<span style="color:#00D">-9</span>, <span style="color:#00D">-4</span>, <span style="color:#00D">-1</span>]
747
+ <span style="color:#080;font-weight:bold">end</span>
748
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
749
+ </div>
750
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_chain_map_source">(<a href="javascript:show('chain_map_source')">show</a>)</span>
751
+ <div class="source" id="chain_map_source"><div class="CodeRay">
752
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
753
+
754
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
755
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">ChainMap</span>
756
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
757
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">chain_map</span>(*args)
758
+ args.inject(<span style="color:#069">self</span>) { |collection, action| collection.map(&amp;action) }
759
+ <span style="color:#080;font-weight:bold">end</span>
760
+ <span style="color:#080;font-weight:bold">end</span>
761
+ <span style="color:#080;font-weight:bold">end</span>
762
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
763
+ </div>
764
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/constantize'" id="constantize">constantize</h3>
765
+ <table class="cube_table"
766
+ id="constantize_cube"
767
+ title="require 'sugar_refinery/constantize'"> <tr><th>Summary</th> <td>Easier handling of dynamic constant names</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
768
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Constantize</span></pre></div>
769
+ </div>
770
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#constantize</h5><div class="usage source" style="display:block"><div class="CodeRay">
771
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Object</span><span style="color:#710">'</span></span>.constantize <span style="color:#777"># =&gt; Object</span>
772
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Spec::VERSION</span><span style="color:#710">'</span></span>.constantize <span style="color:#777"># =&gt; Spec::VERSION if rspec is loaded</span>
773
+ <span style="color:#777"># you can also pass a parameter or block to define what happens, when constant does not exist</span>
774
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">IdontExist</span><span style="color:#710">'</span></span>.constantize(<span style="color:#036;font-weight:bold">Array</span>) <span style="color:#777"># =&gt; Array</span>
775
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String5</span><span style="color:#710">'</span></span>.constantize <span style="color:#080;font-weight:bold">do</span> |string|
776
+ string.chop.constantize
777
+ <span style="color:#080;font-weight:bold">end</span> <span style="color:#777"># =&gt; String</span>
778
+ </pre></div>
779
+ </div>
780
+ </div></td></tr><tr><th>Information</th> <td>An improved version of ActiveSupport's one</td></tr><tr><th>Specification</th> <td> <span id="show_constantize_spec">(<a href="javascript:show('constantize_spec')">show</a>)</span>
781
+ <div class="source" id="constantize_spec"><div class="CodeRay">
782
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/constantize</span><span style="color:#710">'</span></span>
783
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Constantize</span>
784
+
785
+
786
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#constantize</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
787
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should return the constant with that name</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
788
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Object</span><span style="color:#710">'</span></span>.constantize.should == <span style="color:#036;font-weight:bold">Object</span>
789
+ <span style="color:#080;font-weight:bold">end</span>
790
+
791
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should also work for nested constants</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
792
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">SugarRefinery::VERSION</span><span style="color:#710">'</span></span>.constantize.should == <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">VERSION</span>
793
+ <span style="color:#080;font-weight:bold">end</span>
794
+
795
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should throw name error if constant does not exist (and no parameter is given)</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
796
+ proc <span style="color:#080;font-weight:bold">do</span>
797
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ObfsefsefsefafesafaefRubySugarRefineryafdfselijfesject</span><span style="color:#710">'</span></span>.constantize
798
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">NameError</span>
799
+ <span style="color:#080;font-weight:bold">end</span>
800
+
801
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should call the block (and not raise an error) if constant does not exist and block given</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
802
+ proc <span style="color:#080;font-weight:bold">do</span>
803
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ObfsefsefsefafesafaefRubySugarRefineryafdfselijfesject</span><span style="color:#710">'</span></span>.constantize <span style="color:#080;font-weight:bold">do</span> |string|
804
+ <span style="color:#036;font-weight:bold">Default</span> = [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>]
805
+ <span style="color:#080;font-weight:bold">end</span>.should == [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>]
806
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
807
+ <span style="color:#080;font-weight:bold">end</span>
808
+
809
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should return the second parameter (and not raise an error) if constant does not exist and parameter given</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
810
+ proc <span style="color:#080;font-weight:bold">do</span>
811
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ObfsefsefsefafesafaefRubySugarRefineryafdfselijfesject</span><span style="color:#710">'</span></span>.constantize(<span style="color:#036;font-weight:bold">Array</span>).should == <span style="color:#036;font-weight:bold">Array</span>
812
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
813
+ <span style="color:#080;font-weight:bold">end</span>
814
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
815
+ </div>
816
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_constantize_source">(<a href="javascript:show('constantize_source')">show</a>)</span>
817
+ <div class="source" id="constantize_source"><div class="CodeRay">
818
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
819
+
820
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
821
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Constantize</span>
822
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
823
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">constantize</span>(default_value = <span style="color:#069">nil</span>) <span style="color:#777"># always uses global scope as in AS... is this good?</span>
824
+ get_constant = lambda{
825
+ <span style="color:#069">self</span>.split(<span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">::</span><span style="color:#404">/</span></span>).inject( <span style="color:#036;font-weight:bold">Object</span> ){ |base_constant, current_constant|
826
+ base_constant.const_get current_constant
827
+ }
828
+ }
829
+
830
+ <span style="color:#080;font-weight:bold">if</span> !default_value &amp;&amp; !block_given?
831
+ get_constant.call
832
+ <span style="color:#080;font-weight:bold">else</span>
833
+ <span style="color:#080;font-weight:bold">begin</span>
834
+ get_constant.call
835
+ <span style="color:#080;font-weight:bold">rescue</span> <span style="color:#036;font-weight:bold">NameError</span>
836
+ <span style="color:#080;font-weight:bold">if</span> block_given?
837
+ <span style="color:#080;font-weight:bold">yield</span> <span style="color:#069">self</span>
838
+ <span style="color:#080;font-weight:bold">else</span>
839
+ default_value
840
+ <span style="color:#080;font-weight:bold">end</span>
841
+ <span style="color:#080;font-weight:bold">end</span>
842
+ <span style="color:#080;font-weight:bold">end</span>
843
+ <span style="color:#080;font-weight:bold">end</span>
844
+ <span style="color:#080;font-weight:bold">end</span>
845
+ <span style="color:#080;font-weight:bold">end</span>
846
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
847
+ </div>
848
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/dir_utils'" id="dir_utils">dir_utils</h3>
849
+ <table class="cube_table"
850
+ id="dir_utils_cube"
851
+ title="require 'sugar_refinery/dir_utils'"> <tr><th>Summary</th> <td>Some shortcuts for working with directories</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
852
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">DirUtils</span></pre></div>
853
+ </div>
854
+ </div></td></tr><tr><th>Usage</th> <td><h5>Dir.join</h5><div class="usage source" style="display:block"><div class="CodeRay">
855
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.join</pre></div>
856
+ </div>
857
+ </div><h5>Dir.split</h5><div class="usage source" style="display:block"><div class="CodeRay">
858
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.split</pre></div>
859
+ </div>
860
+ </div><h5>Dir.rm</h5><div class="usage source" style="display:block"><div class="CodeRay">
861
+ <div class="code"><pre><span style="color:#036;font-weight:bold">FileUtils</span>.rm_r</pre></div>
862
+ </div>
863
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_dir_utils_spec">(<a href="javascript:show('dir_utils_spec')">show</a>)</span>
864
+ <div class="source" id="dir_utils_spec"><div class="CodeRay">
865
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/dir_utils</span><span style="color:#710">'</span></span>
866
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">securerandom</span><span style="color:#710">'</span></span>
867
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">DirUtils</span>
868
+
869
+
870
+ describe <span style="color:#036;font-weight:bold">Dir</span> <span style="color:#080;font-weight:bold">do</span>
871
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.join</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
872
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">delegates to File.join</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
873
+ a = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w[</span><span style="color:#D20">some file path</span><span style="color:#710">]</span></span>
874
+ expect( <span style="color:#036;font-weight:bold">Dir</span>.join(a) ).to be == <span style="color:#036;font-weight:bold">File</span>.join(a)
875
+ <span style="color:#080;font-weight:bold">end</span>
876
+ <span style="color:#080;font-weight:bold">end</span>
877
+
878
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.split</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
879
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">delegates to File.split</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
880
+ a = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">some/file/path</span><span style="color:#710">'</span></span>
881
+ expect( <span style="color:#036;font-weight:bold">Dir</span>.split(a) ).to be == <span style="color:#036;font-weight:bold">File</span>.split(a)
882
+ <span style="color:#080;font-weight:bold">end</span>
883
+ <span style="color:#080;font-weight:bold">end</span>
884
+
885
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.rm</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
886
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">removes directories with content</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
887
+ path = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">tmp_</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span><span style="color:#036;font-weight:bold">SecureRandom</span>.uuid<span style="font-weight:bold;color:#666">}</span></span><span style="color:#710">&quot;</span></span>
888
+ <span style="color:#036;font-weight:bold">FileUtils</span>.mkdir path
889
+ <span style="color:#036;font-weight:bold">FileUtils</span>.touch <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="background-color:hsla(0,0%,0%,0.07);color:black"><span style="font-weight:bold;color:#666">#{</span>path<span style="font-weight:bold;color:#666">}</span></span><span style="color:#D20">/123</span><span style="color:#710">&quot;</span></span>
890
+ expect{
891
+ <span style="color:#036;font-weight:bold">Dir</span>.rm path
892
+ }.not_to raise_error
893
+ expect( <span style="color:#036;font-weight:bold">Dir</span>[<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">*</span><span style="color:#710">'</span></span>] ).to_not include(path)
894
+ <span style="color:#080;font-weight:bold">end</span>
895
+ <span style="color:#080;font-weight:bold">end</span>
896
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
897
+ </div>
898
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_dir_utils_source">(<a href="javascript:show('dir_utils_source')">show</a>)</span>
899
+ <div class="source" id="dir_utils_source"><div class="CodeRay">
900
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
901
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">fileutils</span><span style="color:#710">'</span></span>
902
+
903
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
904
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">DirUtils</span>
905
+ refine <span style="color:#036;font-weight:bold">Dir</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
906
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">join</span>(*args)
907
+ <span style="color:#036;font-weight:bold">File</span>.join(*args)
908
+ <span style="color:#080;font-weight:bold">end</span>
909
+
910
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">split</span>(*args)
911
+ <span style="color:#036;font-weight:bold">File</span>.split(*args)
912
+ <span style="color:#080;font-weight:bold">end</span>
913
+
914
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">rm</span>(*args)
915
+ <span style="color:#036;font-weight:bold">FileUtils</span>.rm_r(*args)
916
+ <span style="color:#080;font-weight:bold">end</span>
917
+ <span style="color:#080;font-weight:bold">end</span>
918
+ <span style="color:#080;font-weight:bold">end</span>
919
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
920
+ </div>
921
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/file_force_delete'" id="file_force_delete">file_force_delete</h3>
922
+ <table class="cube_table"
923
+ id="file_force_delete_cube"
924
+ title="require 'sugar_refinery/file_force_delete'"> <tr><th>Summary</th> <td><code>File.delete!</code> (like `rm -f`)</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
925
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">FileForceDelete</span></pre></div>
926
+ </div>
927
+ </div></td></tr><tr><th>Usage</th> <td><h5>File.delete!</h5><div class="usage source" style="display:block"><div class="CodeRay">
928
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.delete! <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">some_filename</span><span style="color:#710">'</span></span> <span style="color:#777"># will delete the file, don't care if it exist.</span></pre></div>
929
+ </div>
930
+ </div></td></tr><tr><th>Information</th> <td>Idea for <code>File.delete!</code> from sugar-high.</td></tr><tr><th>Specification</th> <td> <span id="show_file_force_delete_spec">(<a href="javascript:show('file_force_delete_spec')">show</a>)</span>
931
+ <div class="source" id="file_force_delete_spec"><div class="CodeRay">
932
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/file_force_delete</span><span style="color:#710">'</span></span>
933
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">fileutils</span><span style="color:#710">'</span></span>
934
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">FileForceDelete</span>
935
+
936
+
937
+ describe <span style="color:#036;font-weight:bold">File</span> <span style="color:#080;font-weight:bold">do</span>
938
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.delete!</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
939
+ after{ <span style="color:#036;font-weight:bold">File</span>.delete! <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">random_filename</span><span style="color:#710">'</span></span> }
940
+ let <span style="color:#A60">:random_filename</span> <span style="color:#080;font-weight:bold">do</span>
941
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">test_</span><span style="color:#710">'</span></span> + (<span style="color:#00D">0</span>..<span style="color:#00D">20</span>).map{|e| [*<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a</span><span style="color:#710">'</span></span>..<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">z</span><span style="color:#710">'</span></span>].sample }*<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span>
942
+ <span style="color:#080;font-weight:bold">end</span>
943
+
944
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should delete the filename given as argument if it exists + return non-nil</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
945
+ <span style="color:#036;font-weight:bold">FileUtils</span>.touch random_filename
946
+ res = <span style="color:#069">false</span>
947
+ proc <span style="color:#080;font-weight:bold">do</span>
948
+ res = <span style="color:#036;font-weight:bold">File</span>.delete! random_filename
949
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
950
+ res.should be_truthy
951
+ <span style="color:#080;font-weight:bold">end</span>
952
+
953
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should do nothing if the filename given as argument does not exist + return nil</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
954
+ res = <span style="color:#069">false</span>
955
+ proc <span style="color:#080;font-weight:bold">do</span>
956
+ res = <span style="color:#036;font-weight:bold">File</span>.delete! random_filename
957
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
958
+ res.should be_falsey
959
+ <span style="color:#080;font-weight:bold">end</span>
960
+ <span style="color:#080;font-weight:bold">end</span>
961
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
962
+ </div>
963
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_file_force_delete_source">(<a href="javascript:show('file_force_delete_source')">show</a>)</span>
964
+ <div class="source" id="file_force_delete_source"><div class="CodeRay">
965
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
966
+
967
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
968
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">FileForceDelete</span>
969
+ refine <span style="color:#036;font-weight:bold">File</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
970
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">delete!</span>(filename)
971
+ <span style="color:#080;font-weight:bold">return</span> <span style="color:#069">nil</span> <span style="color:#080;font-weight:bold">if</span> !<span style="color:#036;font-weight:bold">File</span>.exist?(filename)
972
+ <span style="color:#036;font-weight:bold">File</span>.delete filename
973
+ <span style="color:#080;font-weight:bold">end</span>
974
+ <span style="color:#080;font-weight:bold">end</span>
975
+ <span style="color:#080;font-weight:bold">end</span>
976
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
977
+ </div>
978
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/file_gsub'" id="file_gsub">file_gsub</h3>
979
+ <table class="cube_table"
980
+ id="file_gsub_cube"
981
+ title="require 'sugar_refinery/file_gsub'"> <tr><th>Summary</th> <td>Will read the file and substitute the hash keys with their values</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
982
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">FileGsub</span></pre></div>
983
+ </div>
984
+ </div></td></tr><tr><th>Usage</th> <td><h5>File.gsub</h5><div class="usage source" style="display:block"><div class="CodeRay">
985
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.gsub <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">some_filename</span><span style="color:#710">'</span></span>,
986
+ <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">hi</span><span style="color:#404">/</span></span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">cu</span><span style="color:#710">'</span></span>,
987
+ <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span> =&gt; proc{ |m| (m.to_i+<span style="color:#00D">1</span>).to_s }
988
+ </pre></div>
989
+ </div>
990
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_file_gsub_spec">(<a href="javascript:show('file_gsub_spec')">show</a>)</span>
991
+ <div class="source" id="file_gsub_spec"><div class="CodeRay">
992
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/file_gsub</span><span style="color:#710">'</span></span>
993
+ require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">fileutils</span><span style="color:#710">'</span></span>
994
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">FileGsub</span>
995
+
996
+
997
+ describe <span style="color:#036;font-weight:bold">File</span> <span style="color:#080;font-weight:bold">do</span>
998
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.gsub</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
999
+ let <span style="color:#A60">:random_filename</span> <span style="color:#080;font-weight:bold">do</span>
1000
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">test_</span><span style="color:#710">'</span></span> + (<span style="color:#00D">0</span>..<span style="color:#00D">20</span>).map{|e| [*<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a</span><span style="color:#710">'</span></span>..<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">z</span><span style="color:#710">'</span></span>].sample }*<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span>
1001
+ <span style="color:#080;font-weight:bold">end</span>
1002
+
1003
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should read filename in arg1, substitute every key in the arg2 with its value and save the file</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1004
+ <span style="color:#036;font-weight:bold">File</span>.open(random_filename,<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">w</span><span style="color:#710">'</span></span>){ |file|
1005
+ file.print <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should read filename in arg1, substitute every key in the arg2 with its value and save the file</span><span style="color:#710">'</span></span>
1006
+ }
1007
+ <span style="color:#036;font-weight:bold">File</span>.gsub random_filename,
1008
+ <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">read</span><span style="color:#404">/</span></span> =&gt; <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">write</span><span style="color:#710">'</span></span>,
1009
+ <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#D20">\d</span><span style="color:#808">+</span><span style="color:#404">/</span></span> =&gt; proc{|m| (m.to_i+<span style="color:#00D">1</span>).to_s }
1010
+
1011
+ <span style="color:#036;font-weight:bold">File</span>.read(random_filename).should ==
1012
+ <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should write filename in arg2, substitute every key in the arg3 with its value and save the file</span><span style="color:#710">'</span></span>
1013
+
1014
+ <span style="color:#036;font-weight:bold">FileUtils</span>.rm random_filename
1015
+ <span style="color:#080;font-weight:bold">end</span>
1016
+ <span style="color:#080;font-weight:bold">end</span>
1017
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1018
+ </div>
1019
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_file_gsub_source">(<a href="javascript:show('file_gsub_source')">show</a>)</span>
1020
+ <div class="source" id="file_gsub_source"><div class="CodeRay">
1021
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1022
+
1023
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1024
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">FileGsub</span>
1025
+ refine <span style="color:#036;font-weight:bold">File</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
1026
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">gsub</span>(filename, regex_hash)
1027
+ data = <span style="color:#036;font-weight:bold">File</span>.read filename
1028
+ <span style="color:#036;font-weight:bold">File</span>.open(filename,<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">w</span><span style="color:#710">'</span></span>){ |file|
1029
+ regex_hash.each{ |regex, new_string|
1030
+ regex = regex.to_s <span style="color:#080;font-weight:bold">unless</span> regex.is_a? <span style="color:#036;font-weight:bold">Regexp</span>
1031
+
1032
+ <span style="color:#080;font-weight:bold">if</span> new_string.is_a? <span style="color:#036;font-weight:bold">Proc</span>
1033
+ data.gsub! regex, &amp;new_string
1034
+ <span style="color:#080;font-weight:bold">else</span>
1035
+ data.gsub! regex, new_string
1036
+ <span style="color:#080;font-weight:bold">end</span>
1037
+ }
1038
+ file.print data
1039
+ }
1040
+ <span style="color:#080;font-weight:bold">end</span>
1041
+ <span style="color:#080;font-weight:bold">end</span>
1042
+ <span style="color:#080;font-weight:bold">end</span>
1043
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1044
+ </div>
1045
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/hash_op'" id="hash_op">hash_op</h3>
1046
+ <table class="cube_table"
1047
+ id="hash_op_cube"
1048
+ title="require 'sugar_refinery/hash_op'"> <tr><th>Summary</th> <td>Sugar for dealing with hashes</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1049
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">HashOp</span></pre></div>
1050
+ </div>
1051
+ </div></td></tr><tr><th>Usage</th> <td><h5>Hash#&lt;&lt;</h5><div class="usage source" style="display:block"><div class="CodeRay">
1052
+ <div class="code"><pre>{<span style="color:#00D">1</span>=&gt;<span style="color:#00D">2</span>} &lt;&lt; [<span style="color:#00D">3</span>, <span style="color:#00D">4</span>] <span style="color:#777"># =&gt; { 1=&gt;2, 3=&gt;4 }</span>
1053
+ {<span style="color:#00D">1</span>=&gt;<span style="color:#00D">2</span>} &lt;&lt; { <span style="color:#00D">5</span>=&gt;<span style="color:#00D">6</span> } <span style="color:#777"># =&gt; { 1=&gt;2, 5=&gt;6 }</span>
1054
+ </pre></div>
1055
+ </div>
1056
+ </div><h5>Hash#&amp;</h5><div class="usage source" style="display:block"><div class="CodeRay">
1057
+ <div class="code"><pre>{ <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span> } &amp; { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">7</span> } <span style="color:#777"># =&gt; { 1=&gt;4 }</span></pre></div>
1058
+ </div>
1059
+ </div></td></tr><tr><th>Information</th> <td>Some of the operators are inspired by Ruby Facets.</td></tr><tr><th>Specification</th> <td> <span id="show_hash_op_spec">(<a href="javascript:show('hash_op_spec')">show</a>)</span>
1060
+ <div class="source" id="hash_op_spec"><div class="CodeRay">
1061
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/hash_op</span><span style="color:#710">'</span></span>
1062
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">HashOp</span>
1063
+
1064
+
1065
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hash#&lt;&lt;</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1066
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">appends new elements to the hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1067
+ a = { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span> }
1068
+ a &lt;&lt; { <span style="color:#00D">4</span>=&gt;<span style="color:#00D">7</span> }
1069
+ a &lt;&lt; [<span style="color:#00D">5</span>, <span style="color:#00D">8</span>]
1070
+ a.should == { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span>, <span style="color:#00D">4</span>=&gt;<span style="color:#00D">7</span>, <span style="color:#00D">5</span>=&gt;<span style="color:#00D">8</span> }
1071
+ <span style="color:#080;font-weight:bold">end</span>
1072
+ <span style="color:#080;font-weight:bold">end</span>
1073
+
1074
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hash#&amp;</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1075
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">selects a sub hash containt only equal key-value pairs</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1076
+ a = { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span> }
1077
+ b = { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">7</span> }
1078
+ (a &amp; b).should == { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span> }
1079
+ <span style="color:#080;font-weight:bold">end</span>
1080
+ <span style="color:#080;font-weight:bold">end</span>
1081
+
1082
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Hash#+</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1083
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">merges two hashes</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1084
+ a = { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span> }
1085
+ b = { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">7</span>, <span style="color:#00D">4</span>=&gt;<span style="color:#00D">0</span> }
1086
+ (a + b).should == { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">7</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span>, <span style="color:#00D">4</span>=&gt;<span style="color:#00D">0</span> }
1087
+ <span style="color:#080;font-weight:bold">end</span>
1088
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1089
+ </div>
1090
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_hash_op_source">(<a href="javascript:show('hash_op_source')">show</a>)</span>
1091
+ <div class="source" id="hash_op_source"><div class="CodeRay">
1092
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1093
+
1094
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1095
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">HashOp</span>
1096
+ refine <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
1097
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">&lt;&lt;</span>(other)
1098
+ <span style="color:#080;font-weight:bold">case</span>
1099
+ <span style="color:#080;font-weight:bold">when</span> other.is_a?(<span style="color:#036;font-weight:bold">Hash</span>)
1100
+ merge! other
1101
+ <span style="color:#080;font-weight:bold">when</span> other.is_a?(<span style="color:#036;font-weight:bold">Enumerable</span>) || other.respond_to?(<span style="color:#A60">:to_splat</span>)
1102
+ merge! <span style="color:#036;font-weight:bold">Hash</span>[*other]
1103
+ <span style="color:#080;font-weight:bold">else</span>
1104
+ raise <span style="color:#036;font-weight:bold">TypeError</span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">can only append other Hashs and Enumerables (or Classes that implement to_splat)</span><span style="color:#710">'</span></span>
1105
+ <span style="color:#080;font-weight:bold">end</span>
1106
+ <span style="color:#080;font-weight:bold">end</span>
1107
+
1108
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">&amp;</span>(other)
1109
+ <span style="color:#036;font-weight:bold">Hash</span>[ *select{ |k,v|
1110
+ other[k] == v
1111
+ }.flatten ]
1112
+ <span style="color:#080;font-weight:bold">end</span>
1113
+
1114
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">+</span>(*o, &amp;block)
1115
+ merge *o, &amp;block
1116
+ <span style="color:#080;font-weight:bold">end</span>
1117
+ <span style="color:#080;font-weight:bold">end</span>
1118
+ <span style="color:#080;font-weight:bold">end</span>
1119
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1120
+ </div>
1121
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/hash_zip'" id="hash_zip">hash_zip</h3>
1122
+ <table class="cube_table"
1123
+ id="hash_zip_cube"
1124
+ title="require 'sugar_refinery/hash_zip'"> <tr><th>Summary</th> <td>Adds a <code>Hash.zip</code> method, which makes sense.</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1125
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">HashZip</span></pre></div>
1126
+ </div>
1127
+ </div></td></tr><tr><th>Usage</th> <td><h5>Hash.zip</h5><div class="usage source" style="display:block"><div class="CodeRay">
1128
+ <div class="code"><pre><span style="color:#036;font-weight:bold">Hash</span>.zip [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>], [<span style="color:#00D">4</span>,<span style="color:#00D">5</span>,<span style="color:#00D">6</span>] <span style="color:#777"># =&gt; {1=&gt;4, 2=&gt;5, 3=&gt;6}</span></pre></div>
1129
+ </div>
1130
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_hash_zip_spec">(<a href="javascript:show('hash_zip_spec')">show</a>)</span>
1131
+ <div class="source" id="hash_zip_spec"><div class="CodeRay">
1132
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/hash_zip</span><span style="color:#710">'</span></span>
1133
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">HashZip</span>
1134
+
1135
+
1136
+ describe <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
1137
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">.zip</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1138
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should zip together both given enumerables and take them as key=&gt;values for a new hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1139
+ <span style="color:#036;font-weight:bold">Hash</span>.zip( [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>], [<span style="color:#00D">4</span>,<span style="color:#00D">5</span>,<span style="color:#00D">6</span>] ).should == { <span style="color:#00D">1</span>=&gt;<span style="color:#00D">4</span>, <span style="color:#00D">2</span>=&gt;<span style="color:#00D">5</span>, <span style="color:#00D">3</span>=&gt;<span style="color:#00D">6</span> }
1140
+ <span style="color:#080;font-weight:bold">end</span>
1141
+ <span style="color:#080;font-weight:bold">end</span>
1142
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1143
+ </div>
1144
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_hash_zip_source">(<a href="javascript:show('hash_zip_source')">show</a>)</span>
1145
+ <div class="source" id="hash_zip_source"><div class="CodeRay">
1146
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1147
+
1148
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1149
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">HashZip</span>
1150
+ refine <span style="color:#036;font-weight:bold">Hash</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
1151
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">zip</span>(keys, values)
1152
+ <span style="color:#036;font-weight:bold">Hash</span>[ *keys.zip(values).flatten ]
1153
+ <span style="color:#080;font-weight:bold">end</span>
1154
+ <span style="color:#080;font-weight:bold">end</span>
1155
+ <span style="color:#080;font-weight:bold">end</span>
1156
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1157
+ </div>
1158
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/inner_map'" id="inner_map">inner_map</h3>
1159
+ <table class="cube_table"
1160
+ id="inner_map_cube"
1161
+ title="require 'sugar_refinery/inner_map'"> <tr><th>Summary</th> <td>Runs blocks on inner <code>Array</code> elements</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1162
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">InnerMap</span></pre></div>
1163
+ </div>
1164
+ </div></td></tr><tr><th>Usage</th> <td><h5>Array#inner_map</h5><div class="usage source" style="display:block"><div class="CodeRay">
1165
+ <div class="code"><pre>[[<span style="color:#00D">1</span>, <span style="color:#00D">2</span>], [<span style="color:#00D">3</span>, <span style="color:#00D">4</span>]].inner_map{ |i| i + <span style="color:#00D">1</span> } <span style="color:#777"># =&gt; [[2, 3], [4, 5]]</span></pre></div>
1166
+ </div>
1167
+ </div><h5>Array#inner_inject</h5><div class="usage source" style="display:block"><div class="CodeRay">
1168
+ <div class="code"><pre>[[<span style="color:#00D">1</span>, <span style="color:#00D">2</span>], [<span style="color:#00D">3</span>, <span style="color:#00D">4</span>]].inner_inject(&amp;<span style="color:#A60">:+</span>) <span style="color:#777"># =&gt; [3, 7]</span></pre></div>
1169
+ </div>
1170
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_inner_map_spec">(<a href="javascript:show('inner_map_spec')">show</a>)</span>
1171
+ <div class="source" id="inner_map_spec"><div class="CodeRay">
1172
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">sugar_refinery/inner_map</span><span style="color:#710">&quot;</span></span>
1173
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">InnerMap</span>
1174
+
1175
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#inner_map</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1176
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate map to inner lists</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1177
+ list = [[<span style="color:#00D">1</span>, <span style="color:#00D">2</span>], [<span style="color:#00D">3</span>, <span style="color:#00D">4</span>]]
1178
+
1179
+ list.inner_map { |i| i + <span style="color:#00D">1</span> }.should == [[<span style="color:#00D">2</span>, <span style="color:#00D">3</span>], [<span style="color:#00D">4</span>, <span style="color:#00D">5</span>]]
1180
+ <span style="color:#080;font-weight:bold">end</span>
1181
+ <span style="color:#080;font-weight:bold">end</span>
1182
+
1183
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Array#inner_inject</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1184
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should delegate inject to inner lists</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1185
+ list = [<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w{</span><span style="color:#D20">a b c</span><span style="color:#710">}</span></span>, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w{</span><span style="color:#D20">d e f</span><span style="color:#710">}</span></span>]
1186
+
1187
+ list.inner_inject(&amp;<span style="color:#A60">:+</span>).should == list.map(&amp;<span style="color:#A60">:join</span>)
1188
+ <span style="color:#080;font-weight:bold">end</span>
1189
+
1190
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">should take default values</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1191
+ list = [[<span style="color:#00D">3</span>, <span style="color:#00D">2</span>, <span style="color:#00D">1</span>], [<span style="color:#00D">-4</span>]]
1192
+
1193
+ list.inner_inject(<span style="color:#00D">4</span>, &amp;<span style="color:#A60">:+</span>).should == [<span style="color:#00D">10</span>, <span style="color:#00D">0</span>]
1194
+ <span style="color:#080;font-weight:bold">end</span>
1195
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1196
+ </div>
1197
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_inner_map_source">(<a href="javascript:show('inner_map_source')">show</a>)</span>
1198
+ <div class="source" id="inner_map_source"><div class="CodeRay">
1199
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1200
+
1201
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1202
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">InnerMap</span>
1203
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
1204
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">inner_map</span>(&amp;block)
1205
+ map { |object| object.map(&amp;block) }
1206
+ <span style="color:#080;font-weight:bold">end</span>
1207
+
1208
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">inner_inject</span>(default = <span style="color:#A60">:not_used</span>, &amp;block)
1209
+ map { |object| default == <span style="color:#A60">:not_used</span> ? object.inject(&amp;block) : object.inject(default, &amp;block) }
1210
+ <span style="color:#080;font-weight:bold">end</span>
1211
+ <span style="color:#080;font-weight:bold">end</span>
1212
+ <span style="color:#080;font-weight:bold">end</span>
1213
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1214
+ </div>
1215
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/lchomp'" id="lchomp">lchomp</h3>
1216
+ <table class="cube_table"
1217
+ id="lchomp_cube"
1218
+ title="require 'sugar_refinery/lchomp'"> <tr><th>Summary</th> <td>Adds <code>String#chomp</code> on the left side.</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1219
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Lchomp</span></pre></div>
1220
+ </div>
1221
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#lchomp</h5><div class="usage source" style="display:block"><div class="CodeRay">
1222
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20"> Yes</span><span style="color:#710">'</span></span>.lchomp <span style="color:#777"># =&gt; ' Yes'</span></pre></div>
1223
+ </div>
1224
+ </div><h5>String#lchomp!</h5><div class="usage source" style="display:block"><div class="CodeRay">
1225
+ <div class="code"><pre><span style="color:#777"># mutable lchomp version</span></pre></div>
1226
+ </div>
1227
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_lchomp_spec">(<a href="javascript:show('lchomp_spec')">show</a>)</span>
1228
+ <div class="source" id="lchomp_spec"><div class="CodeRay">
1229
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/lchomp</span><span style="color:#710">'</span></span>
1230
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Lchomp</span>
1231
+
1232
+ describe <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1233
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">#lchomp</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1234
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should chomp on the left side</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1235
+ string = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ameise</span><span style="color:#710">'</span></span>
1236
+ expect( string.lchomp(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a</span><span style="color:#710">'</span></span>) ).to eq <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">meise</span><span style="color:#710">'</span></span>
1237
+ expect( string ).to eq <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ameise</span><span style="color:#710">'</span></span>
1238
+ <span style="color:#080;font-weight:bold">end</span>
1239
+ <span style="color:#080;font-weight:bold">end</span>
1240
+
1241
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">#lchomp!</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1242
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should chomp on the left side (mutating)</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1243
+ string = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ameise</span><span style="color:#710">'</span></span>
1244
+ expect( string.lchomp!(<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">a</span><span style="color:#710">'</span></span>) ).to eq <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">meise</span><span style="color:#710">'</span></span>
1245
+ expect( string ).to eq <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">meise</span><span style="color:#710">'</span></span>
1246
+ <span style="color:#080;font-weight:bold">end</span>
1247
+ <span style="color:#080;font-weight:bold">end</span>
1248
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1249
+ </div>
1250
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_lchomp_source">(<a href="javascript:show('lchomp_source')">show</a>)</span>
1251
+ <div class="source" id="lchomp_source"><div class="CodeRay">
1252
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1253
+
1254
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1255
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Lchomp</span>
1256
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1257
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">lchomp</span>(arg = <span style="color:#d70">$/</span>)
1258
+ reverse.chomp(arg).reverse
1259
+ <span style="color:#080;font-weight:bold">end</span>
1260
+
1261
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">lchomp!</span>(arg = <span style="color:#d70">$/</span>)
1262
+ replace reverse.chomp(arg).reverse
1263
+ <span style="color:#080;font-weight:bold">end</span>
1264
+ <span style="color:#080;font-weight:bold">end</span>
1265
+ <span style="color:#080;font-weight:bold">end</span>
1266
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1267
+ </div>
1268
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/marshal_copy'" id="marshal_copy">marshal_copy</h3>
1269
+ <table class="cube_table"
1270
+ id="marshal_copy_cube"
1271
+ title="require 'sugar_refinery/marshal_copy'"> <tr><th>Summary</th> <td>Adds <code>Object#marshal_copy</code> to create a deep copy using <code>Marshal</code>.</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1272
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">MarshalCopy</span></pre></div>
1273
+ </div>
1274
+ </div></td></tr><tr><th>Usage</th> <td><h5>Object#marshal_copy</h5><div class="usage source" style="display:block"><div class="CodeRay">
1275
+ <div class="code"><pre>a = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w[</span><span style="color:#D20">hello world</span><span style="color:#710">]</span></span>
1276
+ b = a.marshal_copy
1277
+ </pre></div>
1278
+ </div>
1279
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_marshal_copy_spec">(<a href="javascript:show('marshal_copy_spec')">show</a>)</span>
1280
+ <div class="source" id="marshal_copy_spec"><div class="CodeRay">
1281
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/marshal_copy</span><span style="color:#710">'</span></span>
1282
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">MarshalCopy</span>
1283
+
1284
+
1285
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Object#marshal_copy</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1286
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">create a (deep) copy via marshalling</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1287
+ a = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">%w[</span><span style="color:#D20">hello world</span><span style="color:#710">]</span></span>
1288
+ b = a.marshal_copy
1289
+ b.should == a
1290
+
1291
+ b[<span style="color:#00D">0</span>][<span style="color:#00D">1</span>,<span style="color:#00D">1</span>] = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span>
1292
+ b.should_not == a
1293
+ <span style="color:#080;font-weight:bold">end</span>
1294
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1295
+ </div>
1296
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_marshal_copy_source">(<a href="javascript:show('marshal_copy_source')">show</a>)</span>
1297
+ <div class="source" id="marshal_copy_source"><div class="CodeRay">
1298
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1299
+
1300
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1301
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">MarshalCopy</span>
1302
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
1303
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">marshal_copy</span>
1304
+ <span style="color:#036;font-weight:bold">Marshal</span>.load <span style="color:#036;font-weight:bold">Marshal</span>.dump <span style="color:#069">self</span>
1305
+ <span style="color:#080;font-weight:bold">end</span>
1306
+ <span style="color:#080;font-weight:bold">end</span>
1307
+ <span style="color:#080;font-weight:bold">end</span>
1308
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1309
+ </div>
1310
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/mash'" id="mash">mash</h3>
1311
+ <table class="cube_table"
1312
+ id="mash_cube"
1313
+ title="require 'sugar_refinery/mash'"> <tr><th>Summary</th> <td>mash: map(hash)</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1314
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Mash</span></pre></div>
1315
+ </div>
1316
+ </div></td></tr><tr><th>Usage</th> <td><h5>Enumerable#mash</h5><div class="usage source" style="display:block"><div class="CodeRay">
1317
+ <div class="code"><pre>[<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>].mash{|e| [e, e.to_s] } <span style="color:#777"># =&gt; {1=&gt;'1',2=&gt;'2',3=&gt;'3'}</span></pre></div>
1318
+ </div>
1319
+ </div></td></tr><tr><th>Information</th> <td>Inspired by Ruby Facets' <code>mash</code>.</td></tr><tr><th>Specification</th> <td> <span id="show_mash_spec">(<a href="javascript:show('mash_spec')">show</a>)</span>
1320
+ <div class="source" id="mash_spec"><div class="CodeRay">
1321
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/mash</span><span style="color:#710">'</span></span>
1322
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Mash</span>
1323
+
1324
+
1325
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Array#mash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1326
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should &quot;map&quot; a hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1327
+ [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>].mash{|e| [e, e.to_s] }.should == {<span style="color:#00D">1</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">1</span><span style="color:#710">'</span></span>,<span style="color:#00D">2</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">2</span><span style="color:#710">'</span></span>,<span style="color:#00D">3</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">3</span><span style="color:#710">'</span></span>,}
1328
+ <span style="color:#080;font-weight:bold">end</span>
1329
+ <span style="color:#080;font-weight:bold">end</span>
1330
+
1331
+
1332
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Enumerator#mash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1333
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should &quot;map&quot; a hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1334
+ [<span style="color:#00D">1</span>,<span style="color:#00D">2</span>,<span style="color:#00D">3</span>].each.mash{|e| [e, e.to_s] }.should == {<span style="color:#00D">1</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">1</span><span style="color:#710">'</span></span>,<span style="color:#00D">2</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">2</span><span style="color:#710">'</span></span>,<span style="color:#00D">3</span>=&gt;<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">3</span><span style="color:#710">'</span></span>,}
1335
+ <span style="color:#080;font-weight:bold">end</span>
1336
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1337
+ </div>
1338
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_mash_source">(<a href="javascript:show('mash_source')">show</a>)</span>
1339
+ <div class="source" id="mash_source"><div class="CodeRay">
1340
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1341
+
1342
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1343
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Mash</span>
1344
+ refine <span style="color:#036;font-weight:bold">Enumerator</span> <span style="color:#080;font-weight:bold">do</span>
1345
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">mash</span>
1346
+ ret = {}
1347
+ each{ |kv| ret.store( *(<span style="color:#080;font-weight:bold">yield</span>(kv)[<span style="color:#00D">0</span>,<span style="color:#00D">2</span>]) ) }
1348
+ ret
1349
+ <span style="color:#080;font-weight:bold">end</span>
1350
+ <span style="color:#080;font-weight:bold">end</span>
1351
+
1352
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
1353
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">mash</span>
1354
+ ret = {}
1355
+ each{ |kv| ret.store( *(<span style="color:#080;font-weight:bold">yield</span>(kv)[<span style="color:#00D">0</span>,<span style="color:#00D">2</span>]) ) }
1356
+ ret
1357
+ <span style="color:#080;font-weight:bold">end</span>
1358
+ <span style="color:#080;font-weight:bold">end</span>
1359
+ <span style="color:#080;font-weight:bold">end</span>
1360
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1361
+ </div>
1362
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/regexp_union'" id="regexp_union">regexp_union</h3>
1363
+ <table class="cube_table"
1364
+ id="regexp_union_cube"
1365
+ title="require 'sugar_refinery/regexp_union'"> <tr><th>Summary</th> <td>Easy creation of a <code>Regexp.union</code></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1366
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">RegexpUnion</span></pre></div>
1367
+ </div>
1368
+ </div></td></tr><tr><th>Usage</th> <td><h5>Regexp#|, String#|</h5><div class="usage source" style="display:block"><div class="CodeRay">
1369
+ <div class="code"><pre><span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span> | <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">test</span><span style="color:#404">/</span><span style="color:#C2C">i</span></span> | <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">cheat</span><span style="color:#710">&quot;</span></span>
1370
+ <span style="color:#777"># creates a Regexp similar to:</span>
1371
+ <span style="color:#777"># /(Ruby\d|[tT][eE][sS][tT]|cheat)/</span>
1372
+ </pre></div>
1373
+ </div>
1374
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_regexp_union_spec">(<a href="javascript:show('regexp_union_spec')">show</a>)</span>
1375
+ <div class="source" id="regexp_union_spec"><div class="CodeRay">
1376
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/regexp_union</span><span style="color:#710">'</span></span>
1377
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">RegexpUnion</span>
1378
+
1379
+
1380
+ shared_examples_for <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">Regexp.union operator</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1381
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">creates a Regexp.union of both operands</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1382
+ (<span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span> | <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">test</span><span style="color:#404">/</span><span style="color:#C2C">i</span></span> | <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">cheat</span><span style="color:#710">&quot;</span></span>).should ==
1383
+ <span style="color:#036;font-weight:bold">Regexp</span>.union( <span style="color:#036;font-weight:bold">Regexp</span>.union( <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span>, <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#808">test</span><span style="color:#404">/</span><span style="color:#C2C">i</span></span> ), <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">&quot;</span><span style="color:#D20">cheat</span><span style="color:#710">&quot;</span></span> )
1384
+ <span style="color:#080;font-weight:bold">end</span>
1385
+ <span style="color:#080;font-weight:bold">end</span>
1386
+
1387
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Regexp#|</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1388
+ it_should_behave_like <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Regexp.union operator</span><span style="color:#710">'</span></span>
1389
+ <span style="color:#080;font-weight:bold">end</span>
1390
+
1391
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#|</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1392
+ it_should_behave_like <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Regexp.union operator</span><span style="color:#710">'</span></span>
1393
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1394
+ </div>
1395
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_regexp_union_source">(<a href="javascript:show('regexp_union_source')">show</a>)</span>
1396
+ <div class="source" id="regexp_union_source"><div class="CodeRay">
1397
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1398
+
1399
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1400
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">RegexpUnion</span>
1401
+ refine <span style="color:#036;font-weight:bold">Regexp</span> <span style="color:#080;font-weight:bold">do</span>
1402
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">|</span>(arg)
1403
+ <span style="color:#036;font-weight:bold">Regexp</span>.union <span style="color:#069">self</span>, arg.is_a?(<span style="color:#036;font-weight:bold">Regexp</span>) ? arg : arg.to_s
1404
+ <span style="color:#080;font-weight:bold">end</span>
1405
+ <span style="color:#080;font-weight:bold">end</span>
1406
+
1407
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1408
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">|</span>(arg)
1409
+ <span style="color:#036;font-weight:bold">Regexp</span>.union <span style="color:#069">self</span>, arg.is_a?(<span style="color:#036;font-weight:bold">Regexp</span>) ? arg : arg.to_s
1410
+ <span style="color:#080;font-weight:bold">end</span>
1411
+ <span style="color:#080;font-weight:bold">end</span>
1412
+ <span style="color:#080;font-weight:bold">end</span>
1413
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1414
+ </div>
1415
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/same'" id="same">same</h3>
1416
+ <table class="cube_table"
1417
+ id="same_cube"
1418
+ title="require 'sugar_refinery/same'"> <tr><th>Summary</th> <td>Adds <code>Float#same?</code> for correct number comparisons.</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1419
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Same</span></pre></div>
1420
+ </div>
1421
+ </div></td></tr><tr><th>Usage</th> <td><h5>Float#same?</h5><div class="usage source" style="display:block"><div class="CodeRay">
1422
+ <div class="code"><pre>(<span style="color:#60E">0.1</span> + <span style="color:#60E">0.2</span>).same? <span style="color:#60E">0.3</span> <span style="color:#777"># true</span></pre></div>
1423
+ </div>
1424
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_same_spec">(<a href="javascript:show('same_spec')">show</a>)</span>
1425
+ <div class="source" id="same_spec"><div class="CodeRay">
1426
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/same</span><span style="color:#710">'</span></span>
1427
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">Same</span>
1428
+
1429
+ describe <span style="color:#036;font-weight:bold">Float</span> <span style="color:#080;font-weight:bold">do</span>
1430
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">#same?</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1431
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">returns true if other float represents the same number</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1432
+ expect( <span style="color:#60E">0.3</span>.same?(<span style="color:#60E">0.1</span> + <span style="color:#60E">0.2</span>) ).to be <span style="color:#069">true</span>
1433
+ <span style="color:#080;font-weight:bold">end</span>
1434
+ <span style="color:#080;font-weight:bold">end</span>
1435
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1436
+ </div>
1437
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_same_source">(<a href="javascript:show('same_source')">show</a>)</span>
1438
+ <div class="source" id="same_source"><div class="CodeRay">
1439
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1440
+
1441
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1442
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Same</span>
1443
+ refine <span style="color:#036;font-weight:bold">Float</span> <span style="color:#080;font-weight:bold">do</span>
1444
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">same?</span>(other)
1445
+ (<span style="color:#069">self</span> - other).abs &lt; <span style="color:#036;font-weight:bold">Float</span>::<span style="color:#036;font-weight:bold">EPSILON</span>
1446
+ <span style="color:#080;font-weight:bold">end</span>
1447
+ <span style="color:#080;font-weight:bold">end</span>
1448
+ <span style="color:#080;font-weight:bold">end</span>
1449
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1450
+ </div>
1451
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'sugar_refinery/string_op'" id="string_op">string_op</h3>
1452
+ <table class="cube_table"
1453
+ id="string_op_cube"
1454
+ title="require 'sugar_refinery/string_op'"> <tr><th>Summary</th> <td>More <code>String</code> operators. Because Strings cannot be comfortable enough!</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1455
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">StringOp</span></pre></div>
1456
+ </div>
1457
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#-</h5><div class="usage source" style="display:block"><div class="CodeRay">
1458
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">1234abc5678</span><span style="color:#710">'</span></span> - <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">b</span><span style="color:#710">'</span></span> - <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span> <span style="color:#777"># =&gt; ac</span></pre></div>
1459
+ </div>
1460
+ </div><h5>String#^</h5><div class="usage source" style="display:block"><div class="CodeRay">
1461
+ <div class="code"><pre><span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Yes vs No</span><span style="color:#710">'</span></span>^<span style="color:#00D">2</span> <span style="color:#777"># =&gt; 's vs No'</span></pre></div>
1462
+ </div>
1463
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_string_op_spec">(<a href="javascript:show('string_op_spec')">show</a>)</span>
1464
+ <div class="source" id="string_op_spec"><div class="CodeRay">
1465
+ <div class="code"><pre>require <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">sugar_refinery/string_op</span><span style="color:#710">'</span></span>
1466
+ using <span style="color:#036;font-weight:bold">SugarRefinery</span>::<span style="color:#036;font-weight:bold">StringOp</span>
1467
+
1468
+
1469
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#-</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1470
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should remove the applied Regexp or String from self via gsub</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1471
+ (<span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">1234abc5678</span><span style="color:#710">'</span></span> - <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">b</span><span style="color:#710">'</span></span> - <span style="background-color:hsla(300,100%,50%,0.06)"><span style="color:#404">/</span><span style="color:#D20">\d</span><span style="color:#404">/</span></span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">ac</span><span style="color:#710">'</span></span>
1472
+ <span style="color:#080;font-weight:bold">end</span>
1473
+ <span style="color:#080;font-weight:bold">end</span>
1474
+
1475
+ describe <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">String#^</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1476
+ it <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">should give C-like substring access to strings</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1477
+ string = <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Theoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1478
+
1479
+ (string^<span style="color:#00D">0</span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Theoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1480
+ (string^<span style="color:#00D">1</span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">heoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1481
+ (string^<span style="color:#00D">13</span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1482
+ (string^<span style="color:#00D">-1</span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">Theoretische Informatik ist voll geil</span><span style="color:#710">'</span></span>
1483
+ (string^<span style="color:#00D">38</span>).should == <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span>
1484
+ (string^<span style="color:#00D">99</span>).should == <span style="color:#069">nil</span>
1485
+ <span style="color:#080;font-weight:bold">end</span>
1486
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1487
+ </div>
1488
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_string_op_source">(<a href="javascript:show('string_op_source')">show</a>)</span>
1489
+ <div class="source" id="string_op_source"><div class="CodeRay">
1490
+ <div class="code"><pre>require_relative <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#D20">version</span><span style="color:#710">'</span></span>
1491
+
1492
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SugarRefinery</span>
1493
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">StringOp</span>
1494
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1495
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">-</span>(rem)
1496
+ gsub( <span style="color:#036;font-weight:bold">Regexp</span> === rem ? rem : rem.to_s, <span style="background-color:hsla(0,100%,50%,0.05)"><span style="color:#710">'</span><span style="color:#710">'</span></span> )
1497
+ <span style="color:#080;font-weight:bold">end</span>
1498
+
1499
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">^</span>(pos)
1500
+ pos = pos.to_i
1501
+ <span style="color:#080;font-weight:bold">if</span> pos &gt;= <span style="color:#00D">0</span>
1502
+ <span style="color:#069">self</span>[pos..<span style="color:#00D">-1</span>]
1503
+ <span style="color:#080;font-weight:bold">else</span>
1504
+ <span style="color:#069">self</span>[<span style="color:#00D">0</span>...pos]
1505
+ <span style="color:#080;font-weight:bold">end</span>
1506
+ <span style="color:#080;font-weight:bold">end</span>
1507
+ <span style="color:#080;font-weight:bold">end</span>
1508
+ <span style="color:#080;font-weight:bold">end</span>
1509
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1510
+ </div>
1511
+ </div> </td></tr></table></div>
1512
+
1513
+ <h2>Changelog</h2>
1514
+ <div class="cubes">
1515
+ <pre class="scode"># SUGAR REFINERY CHANGELOG
1516
+
1517
+ ## 2016-01-02 | Sugar Refinery 1.0
1518
+
1519
+ * turn zucker gem into sugar_refinery
1520
+ * move iterate into its own gem
1521
+ * move instance_variable_from into its own gem
1522
+ * move egonil into its own gem
1523
+ * remove 'Zucker#require' and 'Zucker#require_all'
1524
+ * remove 'refine' gem dependency
1525
+ * remove unary_conversion in favor of https://bugs.ruby-lang.org/issues/11782
1526
+ * remove square_brackets_for
1527
+ * remove tap
1528
+ * rename string_extras to lchomp
1529
+ * rename hash_extras to hash_zip
1530
+ * rename float_extras to same
1531
+ * rename dir_extras to dir_utils
1532
+ * split file_extras into file_force_delete and file_gsub (also remove File.filename)
1533
+
1534
+
1535
+ ## OLD ZUCKER CHANGELOG
1536
+
1537
+ 2015-04-01 | Zucker 100.1.0
1538
+ * drop Ruby 1.9 support
1539
+ * add float_extras for Float#same?
1540
+ * add chain_map
1541
+ * add inner_map
1542
+ * add array_stats
1543
+
1544
+
1545
+ 2014-04-01 | Zucker 100.0.0
1546
+ * drop Ruby 1.8 support
1547
+ * rewrite zucker to use refinements!
1548
+ * use usual semantic versioning
1549
+ * remove all "debug" cubes, use the "debugging" gem instead!
1550
+ * remove "ruby_version" cube, use the "ruby_version" gem instead!
1551
+ * remove "engine" cube, use the "ruby_engine" gem instead!
1552
+ * remove "info" cube, use the "ruby_info" gem instead!
1553
+ * remove "os" cube, use rdp's "os" gem instead!
1554
+ * remove "*_to_proc" cubes, use the "procstar" gem instead!
1555
+ * remove "sandbox" cube, since sandboxing is not recommended and removed from Ruby 2.1
1556
+ * remove "kernel" and "not" cube completely
1557
+ * tweaks to most other cubes
1558
+
1559
+
1560
+ 2013-04-30 | Zucker 13
1561
+ * fix alias_for bug
1562
+ * let RubyVersion#inspect and RubyEngine#inspect map to #to_s
1563
+ * remove Array#sum
1564
+ * repackage (gh#4)
1565
+
1566
+
1567
+ 2012-01-16 | Zucker 12
1568
+ * fix a requiring bug
1569
+ * rename zucker/version cube to zucker/ruby_version and Zucker::PACKAGES to Zucker::PACKS
1570
+ * remove more_aliases! (keep it simple...)
1571
+ * add case cube: String#to_camel and String#to_snake
1572
+
1573
+
1574
+ 2011-05-25 | Zucker 11
1575
+ * add Zucker::constants to check if cube has been required (e.g. Zucker::AliasFor if 'zucker/alias_for' is loaded)
1576
+ * rbx tweaks
1577
+ * don't define Binding#vars on rbx (prevent endless recursion)
1578
+ * sandbox-not-working warning
1579
+ * add Kernel#ignore_sigquit!
1580
+ * fix warnings
1581
+ * doc tweaks
1582
+
1583
+
1584
+ 2011-04-29 | Zucker 10
1585
+ * doc/spec tweaks
1586
+ * make test.rubygems.org-testable
1587
+ * fix zucker 9 permission issue
1588
+
1589
+
1590
+ 2011-01-22 | Zucker 9
1591
+ * remove history versions (sorry, it caused too much gem/rdoc troubles)
1592
+ * add file cube: File.delete! and File.gsub
1593
+ * debug pack improvements
1594
+ * binding: typos + return nil
1595
+ * cc: support for ripl + return nil
1596
+ * mm: also show eigenclass for modules + nicer displaying + return nil
1597
+ * added Regexp#visualize
1598
+ * remove optional sandbox param
1599
+ * rename xxx2proc to xxx_to_proc
1600
+ * change rakefile/rspec/gemspec structure
1601
+ * more minor fixes and improvements
1602
+
1603
+
1604
+ 2010-10-06 | Zucker 8
1605
+ * fix a little alias_for bug
1606
+ * disable rdoc creation when installing (in favour of the custom docs)
1607
+ * change Binding#inspect to Binding.variables (was too verbose and dangerous)
1608
+
1609
+
1610
+ 2010-10-03 | Zucker 7
1611
+ * fix critical OS.windows? bug
1612
+
1613
+
1614
+ 2010-10-03 | Zucker 6
1615
+ * no new cubes
1616
+ * bugfix for OS.posix?
1617
+ * small changes + bugfixes + doc improvements
1618
+ * add two user methods to Info
1619
+ * change egonil semantics ( using method_missing, see http://ruby.janlelis.de/26/catch_nil.rb )
1620
+ * bugfix for vv
1621
+
1622
+
1623
+ 2010-09-04 | Zucker 5
1624
+ * debug edition - add two debug helpers: oo (output line, method, file) and cc (output method callstack)
1625
+ * rename cube D to dd add add more debug aliases (for mm and binding)
1626
+ * fix __SPECIAL_VARS__ in info and kernel cube and some minor bugfixes
1627
+ * Zucker.activate_more_aliases! option
1628
+ * add Hash#&amp;
1629
+ * add aliases: File.filename (for basename), Dir.join and Dir.split (for File.join, split)
1630
+ * add a flexible requiring mechansim in zucker.rb (no api changes)
1631
+ * restructure packages
1632
+ * add rake tasks for releasing
1633
+ * improve RubyVersion constant (cleaner and more flexible)
1634
+
1635
+
1636
+ 2010-09-01 | Zucker 4
1637
+ * fix Binding#inspect
1638
+ * add RubyEngine constant
1639
+ * add RubyVersion constant
1640
+ * add OS constant
1641
+ * add q debug method (like p but on one line)
1642
+ * add String#-
1643
+
1644
+
1645
+ 2010-08-14 | Zucker 3
1646
+ * add tap cube
1647
+ * add Object#not
1648
+ * add alias_for for an alternative alias syntax
1649
+ * add String#constantize (improved AS version)
1650
+ * improve Info module
1651
+ * make Array#sum Rails compatibile
1652
+ * improve docs
1653
+ * change directory layout (no changes for requiring)
1654
+ * more small changes
1655
+
1656
+
1657
+ 2010-08-08 | Zucker 2
1658
+ * add info cube
1659
+ * add chaining for array2proc
1660
+ * fix Hash.zip
1661
+ * fix instance_variables_from binding for 1.9
1662
+ * more specs
1663
+
1664
+
1665
+ 2010-08-06 | Zucker 1
1666
+ * initial release
1667
+
1668
+
1669
+ 2010-08-05 | Zucker 0
1670
+ * pre-release for rug-b talk
1671
+
1672
+ </pre>
1673
+ </div>
1674
+ <br/>
1675
+ </div>
1676
+
1677
+ <div id="foot">
1678
+ <div id="smile"><a href="http://janlelis.com">J-_-L</a></div>
1679
+ This is the Ruby Sugar Refinery 1.0.0 documentation (2016-01-03).
1680
+ It is available at <a href="http://janlelis.github.io/sugar_refinery">janlelis.github.io/sugar_refinery</a>.
1681
+ Ruby Logo CC-BY-SA Yukihiro Matsumoto.
1682
+ </div>
1683
+
1684
+ <a href="https://github.com/janlelis/sugar-refinery"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
1685
+ </body>
1686
+ </html>
1687
+