zucker 13.1 → 100.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +17 -2
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +22 -0
  5. data/Rakefile +17 -58
  6. data/doc/{zucker_doc.rb → create_documentation.rb} +67 -129
  7. data/doc/zucker.html +1774 -0
  8. data/lib/zucker.rb +12 -42
  9. data/lib/zucker/alias_for.rb +9 -16
  10. data/lib/zucker/all.rb +0 -2
  11. data/lib/zucker/array_op.rb +15 -0
  12. data/lib/zucker/blank.rb +39 -21
  13. data/lib/zucker/camel_snake.rb +15 -0
  14. data/lib/zucker/constantize.rb +29 -0
  15. data/lib/zucker/dir_extras.rb +20 -0
  16. data/lib/zucker/egonil.rb +13 -24
  17. data/lib/zucker/file_extras.rb +33 -0
  18. data/lib/zucker/hash_extras.rb +11 -0
  19. data/lib/zucker/hash_op.rb +28 -0
  20. data/lib/zucker/instance_variables_from.rb +34 -0
  21. data/lib/zucker/iterate.rb +24 -21
  22. data/lib/zucker/marshal_copy.rb +11 -0
  23. data/lib/zucker/mash.rb +22 -0
  24. data/lib/zucker/ords.rb +17 -0
  25. data/lib/zucker/regexp_union.rb +17 -0
  26. data/lib/zucker/square_brackets_for.rb +12 -15
  27. data/lib/zucker/string_extras.rb +15 -0
  28. data/lib/zucker/string_op.rb +20 -0
  29. data/lib/zucker/tap.rb +13 -8
  30. data/lib/zucker/unary_conversion.rb +25 -0
  31. data/spec/alias_for_spec.rb +11 -73
  32. data/spec/array_op_spec.rb +17 -0
  33. data/spec/blank_spec.rb +2 -0
  34. data/spec/camel_snake_spec.rb +15 -0
  35. data/spec/constantize_spec.rb +33 -0
  36. data/spec/dir_extras_spec.rb +32 -0
  37. data/spec/egonil_spec.rb +1 -0
  38. data/spec/file_extras_spec.rb +57 -0
  39. data/spec/hash_extras_spec.rb +11 -0
  40. data/spec/hash_op_spec.rb +28 -0
  41. data/spec/instance_variables_from_spec.rb +24 -0
  42. data/spec/iterate_spec.rb +2 -0
  43. data/spec/{mcopy_spec.rb → marshal_copy_spec.rb} +5 -3
  44. data/spec/mash_spec.rb +17 -0
  45. data/spec/ords_spec.rb +15 -0
  46. data/spec/{union_spec.rb → regexp_union_spec.rb} +4 -2
  47. data/spec/square_brackets_for_spec.rb +4 -12
  48. data/spec/string_extras_spec.rb +20 -0
  49. data/spec/string_op_spec.rb +22 -0
  50. data/spec/tap_spec.rb +2 -0
  51. data/spec/{unary_spec.rb → unary_conversion_spec.rb} +4 -2
  52. data/zucker.gemspec +8 -18
  53. metadata +75 -147
  54. data/.gemtest +0 -0
  55. data/README +0 -7
  56. data/desc/alias_for.yaml +0 -17
  57. data/desc/aliases.yaml +0 -18
  58. data/desc/array.yaml +0 -11
  59. data/desc/array_to_proc.yaml +0 -16
  60. data/desc/binding.yaml +0 -22
  61. data/desc/blank.yaml +0 -11
  62. data/desc/case.yaml +0 -9
  63. data/desc/cc.yaml +0 -10
  64. data/desc/class_to_proc.yaml +0 -11
  65. data/desc/dd.yaml +0 -23
  66. data/desc/egonil.yaml +0 -15
  67. data/desc/engine.yaml +0 -15
  68. data/desc/enumerable.yaml +0 -10
  69. data/desc/file.yaml +0 -14
  70. data/desc/hash.yaml +0 -14
  71. data/desc/hash_to_proc.yaml +0 -10
  72. data/desc/info.yaml +0 -20
  73. data/desc/iterate.yaml +0 -16
  74. data/desc/ivars.yaml +0 -19
  75. data/desc/kernel.yaml +0 -15
  76. data/desc/mcopy.yaml +0 -11
  77. data/desc/mm.yaml +0 -15
  78. data/desc/not.yaml +0 -11
  79. data/desc/oo.yaml +0 -10
  80. data/desc/os.yaml +0 -19
  81. data/desc/qq.yaml +0 -11
  82. data/desc/regexp_to_proc.yaml +0 -12
  83. data/desc/regexp_visualize.yaml +0 -23
  84. data/desc/ruby_version.yaml +0 -28
  85. data/desc/sandbox.yaml +0 -13
  86. data/desc/square_brackets_for.yaml +0 -22
  87. data/desc/string.yaml +0 -22
  88. data/desc/tap.yaml +0 -17
  89. data/desc/unary.yaml +0 -15
  90. data/desc/union.yaml +0 -10
  91. data/doc/zucker_doc.html +0 -3042
  92. data/lib/zucker/aliases.rb +0 -52
  93. data/lib/zucker/array.rb +0 -15
  94. data/lib/zucker/array_to_proc.rb +0 -19
  95. data/lib/zucker/binding.rb +0 -35
  96. data/lib/zucker/case.rb +0 -14
  97. data/lib/zucker/cc.rb +0 -31
  98. data/lib/zucker/class_to_proc.rb +0 -13
  99. data/lib/zucker/control.rb +0 -4
  100. data/lib/zucker/dd.rb +0 -24
  101. data/lib/zucker/debug.rb +0 -4
  102. data/lib/zucker/default.rb +0 -4
  103. data/lib/zucker/engine.rb +0 -70
  104. data/lib/zucker/enumerable.rb +0 -15
  105. data/lib/zucker/env.rb +0 -4
  106. data/lib/zucker/extensions.rb +0 -4
  107. data/lib/zucker/file.rb +0 -28
  108. data/lib/zucker/hash.rb +0 -28
  109. data/lib/zucker/hash_to_proc.rb +0 -17
  110. data/lib/zucker/info.rb +0 -193
  111. data/lib/zucker/ivars.rb +0 -29
  112. data/lib/zucker/kernel.rb +0 -42
  113. data/lib/zucker/mcopy.rb +0 -11
  114. data/lib/zucker/mm.rb +0 -41
  115. data/lib/zucker/not.rb +0 -20
  116. data/lib/zucker/object.rb +0 -4
  117. data/lib/zucker/oo.rb +0 -18
  118. data/lib/zucker/os.rb +0 -55
  119. data/lib/zucker/qq.rb +0 -13
  120. data/lib/zucker/regexp_to_proc.rb +0 -13
  121. data/lib/zucker/regexp_visualize.rb +0 -31
  122. data/lib/zucker/ruby_version.rb +0 -120
  123. data/lib/zucker/sandbox.rb +0 -17
  124. data/lib/zucker/shortcuts.rb +0 -4
  125. data/lib/zucker/string.rb +0 -55
  126. data/lib/zucker/to_proc.rb +0 -4
  127. data/lib/zucker/unary.rb +0 -25
  128. data/lib/zucker/union.rb +0 -17
  129. data/spec/aliases_spec.rb +0 -13
  130. data/spec/array_spec.rb +0 -16
  131. data/spec/array_to_proc_spec.rb +0 -12
  132. data/spec/binding_spec.rb +0 -6
  133. data/spec/case_spec.rb +0 -15
  134. data/spec/cc_spec.rb +0 -6
  135. data/spec/class_to_proc_spec.rb +0 -9
  136. data/spec/dd_spec.rb +0 -37
  137. data/spec/engine_spec.rb +0 -11
  138. data/spec/enumerable_spec.rb +0 -8
  139. data/spec/file_spec.rb +0 -46
  140. data/spec/hash_spec.rb +0 -25
  141. data/spec/hash_to_proc_spec.rb +0 -12
  142. data/spec/info_spec.rb +0 -8
  143. data/spec/ivars_spec.rb +0 -20
  144. data/spec/kernel_spec.rb +0 -42
  145. data/spec/mm_spec.rb +0 -6
  146. data/spec/not_spec.rb +0 -10
  147. data/spec/oo_spec.rb +0 -6
  148. data/spec/os_spec.rb +0 -37
  149. data/spec/qq_spec.rb +0 -19
  150. data/spec/regexp_to_proc_spec.rb +0 -9
  151. data/spec/regexp_visualize_spec.rb +0 -38
  152. data/spec/ruby_version_spec.rb +0 -55
  153. data/spec/sandbox_spec.rb +0 -14
  154. data/spec/string_spec.rb +0 -65
data/doc/zucker.html ADDED
@@ -0,0 +1,1774 @@
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 Zucker</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.5em;
37
+ }
38
+ h2{
39
+ margin-left:0.5em;
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-right:1.8em;
66
+ padding:0.5em;
67
+ border:1px solid black;
68
+ background:#eee;
69
+ }
70
+
71
+ #.cube_table{
72
+ # display:none;
73
+ #}
74
+ .cubes{
75
+ margin:0px;
76
+ margin-left:1.5em;
77
+ margin-right:1em;
78
+ }
79
+
80
+ a{
81
+ color:#111;
82
+ }
83
+
84
+ table{
85
+ margin:0.8em;
86
+ margin-top:0.2em;
87
+ padding:0.2em;
88
+ border:1px solid #111;
89
+ background:#eee;
90
+ overflow:auto;
91
+ display:block;
92
+ }
93
+
94
+ ul{
95
+ margin:5px 0px !important;
96
+ padding:none;
97
+ }
98
+
99
+ th{
100
+ text-align:left;
101
+ vertical-align:top;
102
+ padding-right:3em;
103
+ }
104
+
105
+ td{
106
+ width:100%;
107
+ }
108
+
109
+ li{
110
+ list-style:none;
111
+ }
112
+
113
+
114
+ #foot{
115
+ text-align:left;
116
+ padding:0.3em;
117
+ font-size:70%
118
+ }
119
+ #foot, #foot a{
120
+ color:#444;
121
+ }
122
+ #smile{
123
+ font-size:150%;
124
+ float:right;
125
+ }
126
+ #smile a{
127
+ text-decoration:none;
128
+ }
129
+
130
+ .small{
131
+ font-size:70%;
132
+ }
133
+
134
+ code, pre{
135
+ font-face:mono;
136
+ margin:0px;
137
+ padding:0px;
138
+ }
139
+
140
+ .source{
141
+ display:none;
142
+ width:98%;
143
+ padding: 3px 5px;
144
+ overflow: auto;
145
+ font-size: 12px;
146
+ background-color: #f8f8f8;
147
+ border:1px solid #005;
148
+ border: 1px solid silver;
149
+ font-family: 'Courier New', 'Terminal', monospace;
150
+ color: #000;
151
+ }
152
+
153
+ # http://coderay.rubychan.de/
154
+ .source pre { margin: 0px; }
155
+
156
+ span.source { white-space: pre; border: 0px; padding: 2px; }
157
+
158
+ table.source { border-collapse: collapse; width: 100%; padding: 2px; }
159
+ table.source td { padding: 2px 4px; vertical-align: top; }
160
+
161
+ .source .line_numbers, .source .no {
162
+ background-color: #def;
163
+ color: gray;
164
+ text-align: right;
165
+ }
166
+ .source .line_numbers a:target, .source .no a:target { color: blue; }
167
+ .source .line_numbers .highlighted, .source .no .highlighted { color: red; }
168
+ .source .no { padding: 0px 4px; }
169
+ .source .code { width: 100%; }
170
+ .source .code pre { overflow: auto; }
171
+
172
+ .source .debug { color:white ! important; background:blue ! important; }
173
+
174
+ .source .an { color:#007 }
175
+ .source .at { color:#f08 }
176
+ .source .av { color:#700 }
177
+ .source .bi { color:#509; font-weight:bold }
178
+ .source .c { color:#888; }
179
+ .source .c .dl { color:#444; }
180
+ .source .c .ch { color:#444; }
181
+
182
+ .source .ch { color:#04D }
183
+ .source .ch .k { color:#04D }
184
+ .source .ch .dl { color:#039 }
185
+
186
+ .source .cl { color:#B06; font-weight:bold }
187
+ .source .cm { color:#A08; font-weight:bold }
188
+ .source .co { color:#036; font-weight:bold }
189
+ .source .cr { color:#0A0 }
190
+ .source .cv { color:#369 }
191
+ .source .de { color:#B0B; }
192
+ .source .df { color:#099; font-weight:bold }
193
+ .source .di { color:#088; font-weight:bold }
194
+ .source .dl { color:black }
195
+ .source .do { color:#970 }
196
+ .source .dt { color:#34b }
197
+ .source .ds { color:#D42; font-weight:bold }
198
+ .source .e { color:#666; font-weight:bold }
199
+ .source .en { color:#800; font-weight:bold }
200
+ .source .er { color:#F00; background-color:#FAA }
201
+ .source .ex { color:#C00; font-weight:bold }
202
+ .source .fl { color:#60E; font-weight:bold }
203
+ .source .fu { color:#06B; font-weight:bold }
204
+ .source .gv { color:#d70; font-weight:bold }
205
+ .source .hx { color:#058; font-weight:bold }
206
+ .source .i { color:#00D; font-weight:bold }
207
+ .source .ic { color:#B44; font-weight:bold }
208
+
209
+ .source .il { background-color: hsla(0,0%,0%,0.1); color: black }
210
+ .source .il .idl { font-weight: bold; color: #666 }
211
+ .source .idl { font-weight: bold; background-color: hsla(0,0%,0%,0.1); color: #666; }
212
+
213
+ .source .im { color:#f00; }
214
+ .source .in { color:#B2B; font-weight:bold }
215
+ .source .iv { color:#33B }
216
+ .source .la { color:#970; font-weight:bold }
217
+ .source .lv { color:#963 }
218
+ .source .ns { color:#707; font-weight:bold }
219
+ .source .oc { color:#40E; font-weight:bold }
220
+ .source .op { }
221
+ .source .pc { color:#058; font-weight:bold }
222
+ .source .pd { color:#369; font-weight:bold }
223
+ .source .pp { color:#579; }
224
+ .source .ps { color:#00C; font-weight:bold }
225
+ .source .pt { color:#074; font-weight:bold }
226
+ .source .r, .kw { color:#080; font-weight:bold }
227
+
228
+ .source .ke { color: #808; }
229
+ .source .ke .dl { color: #606; }
230
+ .source .ke .ch { color: #80f; }
231
+ .source .vl { color: #088; }
232
+
233
+ .source .rx { background-color:hsla(300,100%,50%,0.1); }
234
+ .source .rx .k { color:#808 }
235
+ .source .rx .dl { color:#404 }
236
+ .source .rx .mod { color:#C2C }
237
+ .source .rx .fu { color:#404; font-weight: bold }
238
+
239
+ .source .s { background-color:hsla(0,100%,50%,0.1); }
240
+ .source .s .k { color: #D20; }
241
+ .source .s .ch { color: #b0b; }
242
+ .source .s .dl { color: #710; }
243
+
244
+ .source .sh { background-color:hsla(120,100%,50%,0.1); }
245
+ .source .sh .k { color:#2B2 }
246
+ .source .sh .dl { color:#161 }
247
+
248
+ .source .sy { color:#A60 }
249
+ .source .sy .k { color:#A60 }
250
+ .source .sy .dl { color:#630 }
251
+
252
+ .source .ta { color:#070 }
253
+ .source .ts { color:#D70; font-weight:bold }
254
+ .source .ty { color:#339; font-weight:bold }
255
+ .source .v { color:#036 }
256
+ .source .xt { color:#444 }
257
+
258
+ .source .ins { background: hsla(120,100%,50%,0.2) }
259
+ .source .del { background: hsla(0,100%,50%,0.2) }
260
+ .source .chg { color: #aaf; background: #007; }
261
+ .source .head { color: #f8f; background: #505 }
262
+ .source .head .filename { color: white; }
263
+
264
+ .source .ins .eye { background-color: hsla(120,100%,50%,0.2) }
265
+ .source .del .eye { background-color: hsla(0,100%,50%,0.2) }
266
+
267
+ .source .ins .ins { color: #080; background:transparent; font-weight:bold }
268
+ .source .del .del { color: #800; background:transparent; font-weight:bold }
269
+ .source .chg .chg { color: #66f; }
270
+ .source .head .head { color: #f4f; }
271
+
272
+ .rubylogo{
273
+ margin-left:20px;
274
+ margin-top:10px;
275
+ margin-right:15px;
276
+ float:left;
277
+ }
278
+
279
+ </style>
280
+ </head>
281
+ <body>
282
+ <div id="world">
283
+ <img class="rubylogo" alt="ruby" src="data:image/png;base64,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" />
284
+ <h1>Ruby Zucker</h1>
285
+ <br/>
286
+ <p class="text">Zucker adds syntactic sugar in the form of independent, small scripts that sweeten Ruby even more. It is completely based on Ruby's <a href="#123">refinements</a> feature. You can actively choose for each source file, which features to include. If your Ruby version does not support refinements, plain old core extensions will be used. The source code is available at <a href="https://github.com/janlelis/zucker">github</a>.</p>
287
+
288
+ <h2>Install</h2>
289
+ <p class="text">
290
+ <code class="scode">$ gem install zucker</code>
291
+ Or in your Gemfile:
292
+ <code class="scode">gem 'zucker', require: 'zucker/all'</code>
293
+ </p>
294
+
295
+ <h2>Usage / Organization</h2>
296
+ <p class="text">
297
+ <code class="scode">require 'zucker/all'</code>
298
+ </p>
299
+
300
+ <p class="text">
301
+ Choose which refinements (<em>sugar cubes</em>) you want to use in this Ruby file:
302
+ <div class="cubes">
303
+ <pre class="scode">using Zucker::CamelSnake
304
+ using Zucker::HashExtras
305
+
306
+ "ClassName".to_snake # => "class_name"
307
+ Hash.zip [1,2,3], [4,5,6] # => {1=>4, 2=>5, 3=>6}</pre>
308
+ </div>
309
+ </p>
310
+
311
+ <h2>Refinements</h2>
312
+
313
+ <div class="cubes"><h3 title="require 'zucker/alias_for'" id="alias_for">alias_for</h3>
314
+ <table class="cube_table"
315
+ id="alias_for_cube"
316
+ title="require 'zucker/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">
317
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">AliasFor</span></pre></div>
318
+ </div>
319
+ </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">
320
+ <div class="code"><pre><span style="color:#888"># creates an alias for the method :methods with the name ms</span>
321
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
322
+ alias_for <span style="color:#A60">:methods</span>, <span style="color:#A60">:ms</span>
323
+ <span style="color:#080;font-weight:bold">end</span>
324
+
325
+ <span style="color:#888"># creates multiple aliases</span>
326
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Enumerable</span>
327
+ aliases_for <span style="color:#A60">:zip</span>, <span style="color:#A60">:with</span>, <span style="color:#A60">:%</span>
328
+ <span style="color:#080;font-weight:bold">end</span>
329
+ </pre></div>
330
+ </div>
331
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_alias_for_spec">(<a href="javascript:show('alias_for_spec')">show</a>)</span>
332
+ <div class="source" id="alias_for_spec"><div class="CodeRay">
333
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/alias_for</span><span style="color:#710">'</span></span>
334
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">AliasFor</span>
335
+
336
+
337
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">alias_for</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
338
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should create an alias for instance methods</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
339
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Array</span>
340
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m2</span>
341
+ <span style="color:#00D;font-weight:bold">2</span>
342
+ <span style="color:#080;font-weight:bold">end</span>
343
+ 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:#630">'</span><span style="color:#A60">a-2</span><span style="color:#630">'</span></span>
344
+ <span style="color:#080;font-weight:bold">end</span>
345
+ proc <span style="color:#080;font-weight:bold">do</span>
346
+ [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>].a2.should == <span style="color:#00D;font-weight:bold">2</span>
347
+ [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>].send(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a-2</span><span style="color:#710">'</span></span>).should == <span style="color:#00D;font-weight:bold">2</span>
348
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
349
+ <span style="color:#080;font-weight:bold">end</span>
350
+
351
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should create an alias for class (singleton) methods</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
352
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Array</span>
353
+ <span style="color:#080;font-weight:bold">class</span> &lt;&lt; <span style="color:#B06;font-weight:bold">Array</span>
354
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m3</span>
355
+ <span style="color:#00D;font-weight:bold">3</span>
356
+ <span style="color:#080;font-weight:bold">end</span>
357
+ alias_for <span style="color:#A60">:m3</span>, <span style="color:#A60">:a3</span>
358
+ <span style="color:#080;font-weight:bold">end</span>
359
+ <span style="color:#080;font-weight:bold">end</span>
360
+
361
+ proc{
362
+ <span style="color:#036;font-weight:bold">Array</span>.a3.should == <span style="color:#00D;font-weight:bold">3</span>
363
+ }.should_not raise_exception
364
+ <span style="color:#080;font-weight:bold">end</span>
365
+
366
+
367
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
368
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
369
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">m4</span>
370
+ <span style="color:#00D;font-weight:bold">4</span>
371
+ <span style="color:#080;font-weight:bold">end</span>
372
+ 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>
373
+ <span style="color:#080;font-weight:bold">end</span>
374
+
375
+ proc{
376
+ <span style="color:#00D;font-weight:bold">1</span>.ma.should == <span style="color:#00D;font-weight:bold">4</span>
377
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">1</span><span style="color:#710">&quot;</span></span>.mb.should == <span style="color:#00D;font-weight:bold">4</span>
378
+ [<span style="color:#00D;font-weight:bold">1</span>].mc.should == <span style="color:#00D;font-weight:bold">4</span>
379
+ }.should_not raise_exception
380
+ <span style="color:#080;font-weight:bold">end</span>
381
+
382
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">works with uncommon chars</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
383
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Object</span>
384
+ alias_for <span style="color:#A60">:tainted?</span>, <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#630">&quot;</span><span style="color:#A60">tain-ted?</span><span style="color:#630">&quot;</span></span>
385
+ <span style="color:#080;font-weight:bold">end</span>
386
+ <span style="color:#080;font-weight:bold">end</span>
387
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
388
+ </div>
389
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_alias_for_source">(<a href="javascript:show('alias_for_source')">show</a>)</span>
390
+ <div class="source" id="alias_for_source"><div class="CodeRay">
391
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
392
+
393
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
394
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">AliasFor</span>
395
+ refine <span style="color:#036;font-weight:bold">Module</span> <span style="color:#080;font-weight:bold">do</span>
396
+ private
397
+
398
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">alias_for</span>(m, *aliases)
399
+ aliases.each{ |a| class_eval <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">alias :'</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span> a <span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="">' :'</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span> m <span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="">'</span><span style="color:#710">&quot;</span></span> }
400
+ <span style="color:#080;font-weight:bold">end</span>
401
+
402
+ <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>
403
+ <span style="color:#080;font-weight:bold">end</span>
404
+ <span style="color:#080;font-weight:bold">end</span>
405
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
406
+ </div>
407
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/array_op'" id="array_op">array_op</h3>
408
+ <table class="cube_table"
409
+ id="array_op_cube"
410
+ title="require 'zucker/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">
411
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">ArrayOp</span></pre></div>
412
+ </div>
413
+ </div></td></tr><tr><th>Usage</th> <td><h5>Array#^</h5><div class="usage source" style="display:block"><div class="CodeRay">
414
+ <div class="code"><pre>[<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>,<span style="color:#00D;font-weight:bold">4</span>] ^ [<span style="color:#00D;font-weight:bold">3</span>,<span style="color:#00D;font-weight:bold">4</span>,<span style="color:#00D;font-weight:bold">5</span>,<span style="color:#00D;font-weight:bold">6</span>] <span style="color:#888"># =&gt; [1,2,5,6]</span></pre></div>
415
+ </div>
416
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_array_op_spec">(<a href="javascript:show('array_op_spec')">show</a>)</span>
417
+ <div class="source" id="array_op_spec"><div class="CodeRay">
418
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/array_op</span><span style="color:#710">'</span></span>
419
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">ArrayOp</span>
420
+
421
+
422
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Array#^</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
423
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">does an exclusive or</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
424
+ a = [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>,<span style="color:#00D;font-weight:bold">4</span>]
425
+ b = [<span style="color:#00D;font-weight:bold">3</span>,<span style="color:#00D;font-weight:bold">4</span>,<span style="color:#00D;font-weight:bold">5</span>,<span style="color:#00D;font-weight:bold">6</span>]
426
+ (a^b).should == [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">5</span>,<span style="color:#00D;font-weight:bold">6</span>]
427
+ <span style="color:#080;font-weight:bold">end</span>
428
+ <span style="color:#080;font-weight:bold">end</span>
429
+
430
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Array#**</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
431
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">returns the array product</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
432
+ ([<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>] ** <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">%w[</span><span style="">a b</span><span style="color:#710">]</span></span>).should == [[<span style="color:#00D;font-weight:bold">1</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">a</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D;font-weight:bold">1</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">b</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D;font-weight:bold">2</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">a</span><span style="color:#710">&quot;</span></span>], [<span style="color:#00D;font-weight:bold">2</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">b</span><span style="color:#710">&quot;</span></span>]]
433
+ <span style="color:#080;font-weight:bold">end</span>
434
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
435
+ </div>
436
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_array_op_source">(<a href="javascript:show('array_op_source')">show</a>)</span>
437
+ <div class="source" id="array_op_source"><div class="CodeRay">
438
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
439
+
440
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
441
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">ArrayOp</span>
442
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
443
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">^</span>(other)
444
+ (<span style="color:#038;font-weight:bold">self</span> - other) + (other - <span style="color:#038;font-weight:bold">self</span>)
445
+ <span style="color:#080;font-weight:bold">end</span>
446
+
447
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">**</span>(*o, &amp;block)
448
+ product *o, &amp;block
449
+ <span style="color:#080;font-weight:bold">end</span>
450
+ <span style="color:#080;font-weight:bold">end</span>
451
+ <span style="color:#080;font-weight:bold">end</span>
452
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
453
+ </div>
454
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/blank'" id="blank">blank</h3>
455
+ <table class="cube_table"
456
+ id="blank_cube"
457
+ title="require 'zucker/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">
458
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Blank</span></pre></div>
459
+ </div>
460
+ </div></td></tr><tr><th>Usage</th> <td><h5>Object#blank?</h5><div class="usage source" style="display:block"><div class="CodeRay">
461
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">an object</span><span style="color:#710">'</span></span>.blank? <span style="color:#888"># =&gt; false</span>
462
+ <span style="color:#038;font-weight:bold">nil</span>.present? <span style="color:#888"># =&gt; false</span>
463
+ </pre></div>
464
+ </div>
465
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_blank_spec">(<a href="javascript:show('blank_spec')">show</a>)</span>
466
+ <div class="source" id="blank_spec"><div class="CodeRay">
467
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/blank</span><span style="color:#710">'</span></span>
468
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Blank</span>
469
+
470
+
471
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Object#blank?</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
472
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should be blank for blank values</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
473
+ blank_values = [ <span style="color:#038;font-weight:bold">nil</span>, <span style="color:#038;font-weight:bold">false</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="color:#710">'</span></span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style=""> </span><span style="color:#710">'</span></span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style=""> </span><span style="color:#b0b">\n</span><span style="color:#b0b">\t</span><span style=""> </span><span style="color:#b0b">\r</span><span style=""> </span><span style="color:#710">&quot;</span></span>, [], {}, <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#404">/</span></span> ]
474
+
475
+ blank_values.each{ |blank|
476
+ blank.blank?.should == <span style="color:#038;font-weight:bold">true</span>
477
+ }
478
+ <span style="color:#080;font-weight:bold">end</span>
479
+
480
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should not be blank for non blank values</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
481
+ present_values = [ <span style="color:#036;font-weight:bold">Object</span>.new, <span style="color:#038;font-weight:bold">true</span>, <span style="color:#00D;font-weight:bold">0</span>, <span style="color:#00D;font-weight:bold">1</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>, [<span style="color:#038;font-weight:bold">nil</span>], { <span style="color:#038;font-weight:bold">nil</span> =&gt; <span style="color:#038;font-weight:bold">nil</span> } ]
482
+
483
+ present_values.each{ |present|
484
+ present.blank?.should == <span style="color:#038;font-weight:bold">false</span>
485
+ }
486
+ <span style="color:#080;font-weight:bold">end</span>
487
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
488
+ </div>
489
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_blank_source">(<a href="javascript:show('blank_source')">show</a>)</span>
490
+ <div class="source" id="blank_source"><div class="CodeRay">
491
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
492
+
493
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
494
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Blank</span>
495
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
496
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>
497
+ <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:#038;font-weight:bold">self</span> <span style="color:#080;font-weight:bold">end</span>
498
+ <span style="color:#080;font-weight:bold">end</span>
499
+
500
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">present?</span>
501
+ !blank?
502
+ <span style="color:#080;font-weight:bold">end</span>
503
+ <span style="color:#080;font-weight:bold">end</span>
504
+
505
+ refine <span style="color:#036;font-weight:bold">NilClass</span> <span style="color:#080;font-weight:bold">do</span>
506
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">true</span> <span style="color:#080;font-weight:bold">end</span>
507
+ <span style="color:#080;font-weight:bold">end</span>
508
+
509
+ refine <span style="color:#036;font-weight:bold">FalseClass</span> <span style="color:#080;font-weight:bold">do</span>
510
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">true</span> <span style="color:#080;font-weight:bold">end</span>
511
+ <span style="color:#080;font-weight:bold">end</span>
512
+
513
+ refine <span style="color:#036;font-weight:bold">TrueClass</span> <span style="color:#080;font-weight:bold">do</span>
514
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">false</span> <span style="color:#080;font-weight:bold">end</span>
515
+ <span style="color:#080;font-weight:bold">end</span>
516
+
517
+ refine <span style="color:#036;font-weight:bold">Numeric</span> <span style="color:#080;font-weight:bold">do</span>
518
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">false</span> <span style="color:#080;font-weight:bold">end</span>
519
+ <span style="color:#080;font-weight:bold">end</span>
520
+
521
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
522
+ <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>
523
+ <span style="color:#080;font-weight:bold">end</span>
524
+
525
+ refine <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
526
+ <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>
527
+ <span style="color:#080;font-weight:bold">end</span>
528
+
529
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
530
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">self</span> !~ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\S</span><span style="color:#404">/</span></span> <span style="color:#080;font-weight:bold">end</span>
531
+ <span style="color:#080;font-weight:bold">end</span>
532
+
533
+ refine <span style="color:#036;font-weight:bold">Regexp</span> <span style="color:#080;font-weight:bold">do</span>
534
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">blank?</span>() <span style="color:#038;font-weight:bold">self</span> == <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#404">/</span></span> <span style="color:#080;font-weight:bold">end</span>
535
+ <span style="color:#080;font-weight:bold">end</span>
536
+ <span style="color:#080;font-weight:bold">end</span>
537
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
538
+ </div>
539
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/camel_snake'" id="camel_snake">camel_snake</h3>
540
+ <table class="cube_table"
541
+ id="camel_snake_cube"
542
+ title="require 'zucker/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">
543
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">CamelSnake</span></pre></div>
544
+ </div>
545
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#to_camel</h5><div class="usage source" style="display:block"><div class="CodeRay">
546
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">was_snake_string</span><span style="color:#710">'</span></span>.to_camel <span style="color:#888"># =&gt; 'WasSnakeString'</span></pre></div>
547
+ </div>
548
+ </div><h5>String#to_snake</h5><div class="usage source" style="display:block"><div class="CodeRay">
549
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">WasCamelString</span><span style="color:#710">'</span></span>.to_snake <span style="color:#888"># =&gt; 'was_camel_string'</span></pre></div>
550
+ </div>
551
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_camel_snake_spec">(<a href="javascript:show('camel_snake_spec')">show</a>)</span>
552
+ <div class="source" id="camel_snake_spec"><div class="CodeRay">
553
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/camel_snake</span><span style="color:#710">'</span></span>
554
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">CamelSnake</span>
555
+
556
+
557
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#to_camel</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
558
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should turn a snake_cased string to CamelCase</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
559
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">was_snake_case</span><span style="color:#710">'</span></span>.to_camel.should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">WasSnakeCase</span><span style="color:#710">'</span></span>
560
+ <span style="color:#080;font-weight:bold">end</span>
561
+ <span style="color:#080;font-weight:bold">end</span>
562
+
563
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#to_snake</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
564
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should turn a CamelCased string to snake_case</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
565
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">WasCamelCase</span><span style="color:#710">'</span></span>.to_snake.should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">was_camel_case</span><span style="color:#710">'</span></span>
566
+ <span style="color:#080;font-weight:bold">end</span>
567
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
568
+ </div>
569
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_camel_snake_source">(<a href="javascript:show('camel_snake_source')">show</a>)</span>
570
+ <div class="source" id="camel_snake_source"><div class="CodeRay">
571
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
572
+
573
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
574
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">CamelSnake</span>
575
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
576
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">to_snake</span>
577
+ gsub(<span style="background-color:#fff0ff"><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:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">_</span><span style="color:#710">#</span><span style="color:#d70;font-weight:bold">$&amp;</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">end</span>.downcase
578
+ <span style="color:#080;font-weight:bold">end</span>
579
+
580
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">to_camel</span>
581
+ gsub(<span style="background-color:#fff0ff"><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;font-weight:bold">$1</span>.upcase <span style="color:#080;font-weight:bold">end</span>
582
+ <span style="color:#080;font-weight:bold">end</span>
583
+ <span style="color:#080;font-weight:bold">end</span>
584
+ <span style="color:#080;font-weight:bold">end</span>
585
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
586
+ </div>
587
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/constantize'" id="constantize">constantize</h3>
588
+ <table class="cube_table"
589
+ id="constantize_cube"
590
+ title="require 'zucker/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">
591
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Constantize</span></pre></div>
592
+ </div>
593
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#constantize</h5><div class="usage source" style="display:block"><div class="CodeRay">
594
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Object</span><span style="color:#710">'</span></span>.constantize <span style="color:#888"># =&gt; Object</span>
595
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Spec::VERSION</span><span style="color:#710">'</span></span>.constantize <span style="color:#888"># =&gt; Spec::VERSION if rspec is loaded</span>
596
+ <span style="color:#888"># you can also pass a parameter or block to define what happens, when constant does not exist</span>
597
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">IdontExist</span><span style="color:#710">'</span></span>.constantize(<span style="color:#036;font-weight:bold">Array</span>) <span style="color:#888"># =&gt; Array</span>
598
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String5</span><span style="color:#710">'</span></span>.constantize <span style="color:#080;font-weight:bold">do</span> |string|
599
+ string.chop.constantize
600
+ <span style="color:#080;font-weight:bold">end</span> <span style="color:#888"># =&gt; String</span>
601
+ </pre></div>
602
+ </div>
603
+ </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>
604
+ <div class="source" id="constantize_spec"><div class="CodeRay">
605
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/constantize</span><span style="color:#710">'</span></span>
606
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Constantize</span>
607
+
608
+
609
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#constantize</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
610
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should return the constant with that name</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
611
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Object</span><span style="color:#710">'</span></span>.constantize.should == <span style="color:#036;font-weight:bold">Object</span>
612
+ <span style="color:#080;font-weight:bold">end</span>
613
+
614
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should also work for nested constants</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
615
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Zucker::VERSION</span><span style="color:#710">'</span></span>.constantize.should == <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">VERSION</span>
616
+ <span style="color:#080;font-weight:bold">end</span>
617
+
618
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
619
+ proc <span style="color:#080;font-weight:bold">do</span>
620
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ObfsefsefsefafesafaefRubyZuckerafdfselijfesject</span><span style="color:#710">'</span></span>.constantize
621
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">NameError</span>
622
+ <span style="color:#080;font-weight:bold">end</span>
623
+
624
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
625
+ proc <span style="color:#080;font-weight:bold">do</span>
626
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ObfsefsefsefafesafaefRubyZuckerafdfselijfesject</span><span style="color:#710">'</span></span>.constantize <span style="color:#080;font-weight:bold">do</span> |string|
627
+ <span style="color:#036;font-weight:bold">Default</span> = [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>]
628
+ <span style="color:#080;font-weight:bold">end</span>.should == [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>]
629
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
630
+ <span style="color:#080;font-weight:bold">end</span>
631
+
632
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
633
+ proc <span style="color:#080;font-weight:bold">do</span>
634
+ <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ObfsefsefsefafesafaefRubyZuckerafdfselijfesject</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>
635
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
636
+ <span style="color:#080;font-weight:bold">end</span>
637
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
638
+ </div>
639
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_constantize_source">(<a href="javascript:show('constantize_source')">show</a>)</span>
640
+ <div class="source" id="constantize_source"><div class="CodeRay">
641
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
642
+
643
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
644
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Constantize</span>
645
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
646
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">constantize</span>(default_value = <span style="color:#038;font-weight:bold">nil</span>) <span style="color:#888"># always uses global scope as in AS... is this good?</span>
647
+ get_constant = lambda{
648
+ <span style="color:#038;font-weight:bold">self</span>.split(<span style="background-color:#fff0ff"><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|
649
+ base_constant.const_get current_constant
650
+ }
651
+ }
652
+
653
+ <span style="color:#080;font-weight:bold">if</span> !default_value &amp;&amp; !block_given?
654
+ get_constant.call
655
+ <span style="color:#080;font-weight:bold">else</span>
656
+ <span style="color:#080;font-weight:bold">begin</span>
657
+ get_constant.call
658
+ <span style="color:#080;font-weight:bold">rescue</span> <span style="color:#036;font-weight:bold">NameError</span>
659
+ <span style="color:#080;font-weight:bold">if</span> block_given?
660
+ <span style="color:#080;font-weight:bold">yield</span> <span style="color:#038;font-weight:bold">self</span>
661
+ <span style="color:#080;font-weight:bold">else</span>
662
+ default_value
663
+ <span style="color:#080;font-weight:bold">end</span>
664
+ <span style="color:#080;font-weight:bold">end</span>
665
+ <span style="color:#080;font-weight:bold">end</span>
666
+ <span style="color:#080;font-weight:bold">end</span>
667
+ <span style="color:#080;font-weight:bold">end</span>
668
+ <span style="color:#080;font-weight:bold">end</span>
669
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
670
+ </div>
671
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/dir_extras'" id="dir_extras">dir_extras</h3>
672
+ <table class="cube_table"
673
+ id="dir_extras_cube"
674
+ title="require 'zucker/dir_extras'"> <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">
675
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">DirExtras</span></pre></div>
676
+ </div>
677
+ </div></td></tr><tr><th>Usage</th> <td><h5>Dir.join</h5><div class="usage source" style="display:block"><div class="CodeRay">
678
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.join</pre></div>
679
+ </div>
680
+ </div><h5>Dir.split</h5><div class="usage source" style="display:block"><div class="CodeRay">
681
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.split</pre></div>
682
+ </div>
683
+ </div><h5>Dir.rm</h5><div class="usage source" style="display:block"><div class="CodeRay">
684
+ <div class="code"><pre><span style="color:#036;font-weight:bold">FileUtils</span>.rm_r</pre></div>
685
+ </div>
686
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_dir_extras_spec">(<a href="javascript:show('dir_extras_spec')">show</a>)</span>
687
+ <div class="source" id="dir_extras_spec"><div class="CodeRay">
688
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/dir_extras</span><span style="color:#710">'</span></span>
689
+ require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">securerandom</span><span style="color:#710">'</span></span>
690
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">DirExtras</span>
691
+
692
+
693
+ describe <span style="color:#036;font-weight:bold">Dir</span> <span style="color:#080;font-weight:bold">do</span>
694
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">.join</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
695
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">delegates to File.join</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
696
+ a = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">%w[</span><span style="">some file path</span><span style="color:#710">]</span></span>
697
+ 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)
698
+ <span style="color:#080;font-weight:bold">end</span>
699
+ <span style="color:#080;font-weight:bold">end</span>
700
+
701
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">.split</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
702
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">delegates to File.split</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
703
+ a = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">some/file/path</span><span style="color:#710">'</span></span>
704
+ 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)
705
+ <span style="color:#080;font-weight:bold">end</span>
706
+ <span style="color:#080;font-weight:bold">end</span>
707
+
708
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">.rm</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
709
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">removes directories with content</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
710
+ path = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">tmp_</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span><span style="color:#036;font-weight:bold">SecureRandom</span>.uuid<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#710">&quot;</span></span>
711
+ <span style="color:#036;font-weight:bold">FileUtils</span>.mkdir path
712
+ <span style="color:#036;font-weight:bold">FileUtils</span>.touch <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>path<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="">/123</span><span style="color:#710">&quot;</span></span>
713
+ expect{
714
+ <span style="color:#036;font-weight:bold">Dir</span>.rm path
715
+ }.not_to raise_error
716
+ expect( <span style="color:#036;font-weight:bold">Dir</span>[<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">*</span><span style="color:#710">'</span></span>] ).to_not include(path)
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></pre></div>
720
+ </div>
721
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_dir_extras_source">(<a href="javascript:show('dir_extras_source')">show</a>)</span>
722
+ <div class="source" id="dir_extras_source"><div class="CodeRay">
723
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
724
+ require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">fileutils</span><span style="color:#710">'</span></span>
725
+
726
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
727
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">DirExtras</span>
728
+ refine <span style="color:#036;font-weight:bold">Dir</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
729
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">join</span>(*args)
730
+ <span style="color:#036;font-weight:bold">File</span>.join(*args)
731
+ <span style="color:#080;font-weight:bold">end</span>
732
+
733
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">split</span>(*args)
734
+ <span style="color:#036;font-weight:bold">File</span>.split(*args)
735
+ <span style="color:#080;font-weight:bold">end</span>
736
+
737
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">rm</span>(*args)
738
+ <span style="color:#036;font-weight:bold">FileUtils</span>.rm_r(*args)
739
+ <span style="color:#080;font-weight:bold">end</span>
740
+ <span style="color:#080;font-weight:bold">end</span>
741
+ <span style="color:#080;font-weight:bold">end</span>
742
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
743
+ </div>
744
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/egonil'" id="egonil">egonil</h3>
745
+ <table class="cube_table"
746
+ id="egonil_cube"
747
+ title="require 'zucker/egonil'"> <tr><th>Summary</th> <td>Creates a block, where <code>nil</code> does not raise <code>NoMethodError</code>s</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
748
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Egonil</span></pre></div>
749
+ </div>
750
+ </div></td></tr><tr><th>Usage</th> <td><h5>egonil</h5><div class="usage source" style="display:block"><div class="CodeRay">
751
+ <div class="code"><pre>egonil{
752
+ <span style="color:#038;font-weight:bold">nil</span>.some_methods.that[<span style="color:#A60">:do</span>].not.exist
753
+ }
754
+ </pre></div>
755
+ </div>
756
+ </div></td></tr><tr><th>Information</th> <td>See <a href="http://rbjl.net/26-the-28-bytes-of-ruby-joy">this post</a> for more information and discussion.</td></tr><tr><th>Specification</th> <td> <span id="show_egonil_spec">(<a href="javascript:show('egonil_spec')">show</a>)</span>
757
+ <div class="source" id="egonil_spec"><div class="CodeRay">
758
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/egonil</span><span style="color:#710">'</span></span>
759
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Egonil</span>
760
+
761
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">egonil</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
762
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should not raise nil exceptions in the block</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
763
+ proc <span style="color:#080;font-weight:bold">do</span>
764
+ egonil{ <span style="color:#038;font-weight:bold">nil</span>.some_methods.that[<span style="color:#A60">:do</span>].not.exist }
765
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
766
+ <span style="color:#080;font-weight:bold">end</span>
767
+
768
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should restore default behaviour after the block</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
769
+ proc <span style="color:#080;font-weight:bold">do</span>
770
+ egonil{ <span style="color:#038;font-weight:bold">nil</span>.some_methods.that[<span style="color:#A60">:do</span>].not.exist }
771
+ <span style="color:#080;font-weight:bold">end</span>.should_not raise_exception
772
+
773
+ proc <span style="color:#080;font-weight:bold">do</span>
774
+ <span style="color:#038;font-weight:bold">nil</span>.a_method
775
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">NoMethodError</span>
776
+ <span style="color:#080;font-weight:bold">end</span>
777
+
778
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">raise NoMethodError for non-nil objects</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
779
+ proc <span style="color:#080;font-weight:bold">do</span>
780
+ egonil{ <span style="color:#00D;font-weight:bold">5</span>.a_method }
781
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">NoMethodError</span>
782
+ <span style="color:#080;font-weight:bold">end</span>
783
+
784
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should raise other Exceptions</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
785
+ proc <span style="color:#080;font-weight:bold">do</span>
786
+ egonil{ <span style="color:#00D;font-weight:bold">5</span> / <span style="color:#00D;font-weight:bold">0</span> }
787
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">ZeroDivisionError</span>
788
+ <span style="color:#080;font-weight:bold">end</span>
789
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
790
+ </div>
791
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_egonil_source">(<a href="javascript:show('egonil_source')">show</a>)</span>
792
+ <div class="source" id="egonil_source"><div class="CodeRay">
793
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
794
+
795
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
796
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Egonil</span>
797
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
798
+ private
799
+
800
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">egonil</span>(&amp;block)
801
+ mm = <span style="color:#036;font-weight:bold">NilClass</span>.instance_method(<span style="color:#A60">:method_missing</span>)
802
+ <span style="color:#036;font-weight:bold">NilClass</span>.send <span style="color:#A60">:define_method</span>, <span style="color:#A60">:method_missing</span>, -&gt;(*){}
803
+ <span style="color:#080;font-weight:bold">yield</span>
804
+ <span style="color:#080;font-weight:bold">ensure</span>
805
+ <span style="color:#036;font-weight:bold">NilClass</span>.send <span style="color:#A60">:define_method</span>, <span style="color:#A60">:method_missing</span>, mm
806
+ <span style="color:#080;font-weight:bold">end</span>
807
+ <span style="color:#080;font-weight:bold">end</span>
808
+ <span style="color:#080;font-weight:bold">end</span>
809
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
810
+ </div>
811
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/file'" id="file">file</h3>
812
+ <table class="cube_table"
813
+ id="file_cube"
814
+ title="require 'zucker/file'"> <tr><th>Summary</th> <td>Extensions for <code>File</code></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
815
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">File</span></pre></div>
816
+ </div>
817
+ </div></td></tr><tr><th>Usage</th> <td><h5>File.gsub</h5><div class="usage source" style="display:block"><div class="CodeRay">
818
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.gsub <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">some_filename</span><span style="color:#710">'</span></span>, <span style="color:#888"># will read the file and substitute the hash keys with their values</span>
819
+ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">hi</span><span style="color:#404">/</span></span> =&gt; <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">cu</span><span style="color:#710">'</span></span>,
820
+ <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span> =&gt; proc{ |m| (m.to_i+<span style="color:#00D;font-weight:bold">1</span>).to_s }
821
+ </pre></div>
822
+ </div>
823
+ </div><h5>File.delete!</h5><div class="usage source" style="display:block"><div class="CodeRay">
824
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.delete! <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">some_filename</span><span style="color:#710">'</span></span> <span style="color:#888"># will delete the file, don't care if it exist.</span></pre></div>
825
+ </div>
826
+ </div><h5>File.filename</h5><div class="usage source" style="display:block"><div class="CodeRay">
827
+ <div class="code"><pre><span style="color:#036;font-weight:bold">File</span>.basename</pre></div>
828
+ </div>
829
+ </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_spec">(<a href="javascript:show('file_spec')">show</a>)</span>
830
+ <div class="source" id="file_spec"><em>FIXME: missing (please create a <a href="http://github.com/janlelis/zucker/issues">github issue</a>)</em></div> </td></tr><tr><th>Source</th> <td> <span id="show_file_source">(<a href="javascript:show('file_source')">show</a>)</span>
831
+ <div class="source" id="file_source"><em>FIXME: missing (please create a <a href="http://github.com/janlelis/zucker/issues">github issue</a>)</em></div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/hash_extras'" id="hash_extras">hash_extras</h3>
832
+ <table class="cube_table"
833
+ id="hash_extras_cube"
834
+ title="require 'zucker/hash_extras'"> <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">
835
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">HashExtras</span></pre></div>
836
+ </div>
837
+ </div></td></tr><tr><th>Usage</th> <td><h5>Hash.zip</h5><div class="usage source" style="display:block"><div class="CodeRay">
838
+ <div class="code"><pre><span style="color:#036;font-weight:bold">Hash</span>.zip [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>], [<span style="color:#00D;font-weight:bold">4</span>,<span style="color:#00D;font-weight:bold">5</span>,<span style="color:#00D;font-weight:bold">6</span>] <span style="color:#888"># =&gt; {1=&gt;4, 2=&gt;5, 3=&gt;6}</span></pre></div>
839
+ </div>
840
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_hash_extras_spec">(<a href="javascript:show('hash_extras_spec')">show</a>)</span>
841
+ <div class="source" id="hash_extras_spec"><div class="CodeRay">
842
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/hash_extras</span><span style="color:#710">'</span></span>
843
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">HashExtras</span>
844
+
845
+
846
+ describe <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
847
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">.zip</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
848
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
849
+ <span style="color:#036;font-weight:bold">Hash</span>.zip( [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>], [<span style="color:#00D;font-weight:bold">4</span>,<span style="color:#00D;font-weight:bold">5</span>,<span style="color:#00D;font-weight:bold">6</span>] ).should == { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> }
850
+ <span style="color:#080;font-weight:bold">end</span>
851
+ <span style="color:#080;font-weight:bold">end</span>
852
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
853
+ </div>
854
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_hash_extras_source">(<a href="javascript:show('hash_extras_source')">show</a>)</span>
855
+ <div class="source" id="hash_extras_source"><div class="CodeRay">
856
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
857
+
858
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
859
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">HashExtras</span>
860
+ refine <span style="color:#036;font-weight:bold">Hash</span>.singleton_class <span style="color:#080;font-weight:bold">do</span>
861
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">zip</span>(keys, values)
862
+ <span style="color:#036;font-weight:bold">Hash</span>[ *keys.zip(values).flatten ]
863
+ <span style="color:#080;font-weight:bold">end</span>
864
+ <span style="color:#080;font-weight:bold">end</span>
865
+ <span style="color:#080;font-weight:bold">end</span>
866
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
867
+ </div>
868
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/hash_op'" id="hash_op">hash_op</h3>
869
+ <table class="cube_table"
870
+ id="hash_op_cube"
871
+ title="require 'zucker/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">
872
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">HashOp</span></pre></div>
873
+ </div>
874
+ </div></td></tr><tr><th>Usage</th> <td><h5>Hash#&lt;&lt;</h5><div class="usage source" style="display:block"><div class="CodeRay">
875
+ <div class="code"><pre>{<span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">2</span>} &lt;&lt; [<span style="color:#00D;font-weight:bold">3</span>, <span style="color:#00D;font-weight:bold">4</span>] <span style="color:#888"># =&gt; { 1=&gt;2, 3=&gt;4 }</span>
876
+ {<span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">2</span>} &lt;&lt; { <span style="color:#00D;font-weight:bold">5</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> } <span style="color:#888"># =&gt; { 1=&gt;2, 5=&gt;6 }</span>
877
+ </pre></div>
878
+ </div>
879
+ </div><h5>Hash#&amp;</h5><div class="usage source" style="display:block"><div class="CodeRay">
880
+ <div class="code"><pre>{ <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> } &amp; { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">7</span> } <span style="color:#888"># =&gt; { 1=&gt;4 }</span></pre></div>
881
+ </div>
882
+ </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>
883
+ <div class="source" id="hash_op_spec"><div class="CodeRay">
884
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/hash_op</span><span style="color:#710">'</span></span>
885
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">HashOp</span>
886
+
887
+
888
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Hash#&lt;&lt;</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
889
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">appends new elements to the hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
890
+ a = { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> }
891
+ a &lt;&lt; { <span style="color:#00D;font-weight:bold">4</span>=&gt;<span style="color:#00D;font-weight:bold">7</span> }
892
+ a &lt;&lt; [<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">8</span>]
893
+ a.should == { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span>, <span style="color:#00D;font-weight:bold">4</span>=&gt;<span style="color:#00D;font-weight:bold">7</span>, <span style="color:#00D;font-weight:bold">5</span>=&gt;<span style="color:#00D;font-weight:bold">8</span> }
894
+ <span style="color:#080;font-weight:bold">end</span>
895
+ <span style="color:#080;font-weight:bold">end</span>
896
+
897
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Hash#&amp;</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
898
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
899
+ a = { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> }
900
+ b = { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">7</span> }
901
+ (a &amp; b).should == { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span> }
902
+ <span style="color:#080;font-weight:bold">end</span>
903
+ <span style="color:#080;font-weight:bold">end</span>
904
+
905
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Hash#+</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
906
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">merges two hashes</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
907
+ a = { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">5</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span> }
908
+ b = { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">7</span>, <span style="color:#00D;font-weight:bold">4</span>=&gt;<span style="color:#00D;font-weight:bold">0</span> }
909
+ (a + b).should == { <span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="color:#00D;font-weight:bold">4</span>, <span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="color:#00D;font-weight:bold">7</span>, <span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="color:#00D;font-weight:bold">6</span>, <span style="color:#00D;font-weight:bold">4</span>=&gt;<span style="color:#00D;font-weight:bold">0</span> }
910
+ <span style="color:#080;font-weight:bold">end</span>
911
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
912
+ </div>
913
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_hash_op_source">(<a href="javascript:show('hash_op_source')">show</a>)</span>
914
+ <div class="source" id="hash_op_source"><div class="CodeRay">
915
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
916
+
917
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
918
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">HashOp</span>
919
+ refine <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span>
920
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">&lt;&lt;</span>(other)
921
+ <span style="color:#080;font-weight:bold">case</span>
922
+ <span style="color:#080;font-weight:bold">when</span> other.is_a?(<span style="color:#036;font-weight:bold">Hash</span>)
923
+ merge! other
924
+ <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>)
925
+ merge! <span style="color:#036;font-weight:bold">Hash</span>[*other]
926
+ <span style="color:#080;font-weight:bold">else</span>
927
+ raise <span style="color:#036;font-weight:bold">TypeError</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">can only append other Hashs and Enumerables (or Classes that implement to_splat)</span><span style="color:#710">'</span></span>
928
+ <span style="color:#080;font-weight:bold">end</span>
929
+ <span style="color:#080;font-weight:bold">end</span>
930
+
931
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">&amp;</span>(other)
932
+ <span style="color:#036;font-weight:bold">Hash</span>[ *select{ |k,v|
933
+ other[k] == v
934
+ }.flatten ]
935
+ <span style="color:#080;font-weight:bold">end</span>
936
+
937
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">+</span>(*o, &amp;block)
938
+ merge *o, &amp;block
939
+ <span style="color:#080;font-weight:bold">end</span>
940
+ <span style="color:#080;font-weight:bold">end</span>
941
+ <span style="color:#080;font-weight:bold">end</span>
942
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
943
+ </div>
944
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/instance_variables_from'" id="instance_variables_from">instance_variables_from</h3>
945
+ <table class="cube_table"
946
+ id="instance_variables_from_cube"
947
+ title="require 'zucker/instance_variables_from'"> <tr><th>Summary</th> <td>Reduces boilerplate code assigning lots of instance variables:<br/><br/><code>def initialize(variable1, variable2)<br/>  @variable1, @variable2 = variable1, variable2<br/>end</code><br/></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
948
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">InstanceVariablesFrom</span></pre></div>
949
+ </div>
950
+ </div></td></tr><tr><th>Usage</th> <td><h5>instance_variables_from</h5><div class="usage source" style="display:block"><div class="CodeRay">
951
+ <div class="code"><pre><span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">some_method</span>(a = <span style="color:#00D;font-weight:bold">1</span>, b = <span style="color:#00D;font-weight:bold">2</span>)
952
+ instance_variables_from binding <span style="color:#888"># assigns @a and @b</span>
953
+
954
+ params = {<span style="color:#A60">:c</span> =&gt; <span style="color:#00D;font-weight:bold">3</span>, <span style="color:#A60">:d</span> =&gt; <span style="color:#00D;font-weight:bold">4</span>}
955
+ instance_variables_from params <span style="color:#888"># # assigns @c and @d</span>
956
+ <span style="color:#080;font-weight:bold">end</span>
957
+ </pre></div>
958
+ </div>
959
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_instance_variables_from_spec">(<a href="javascript:show('instance_variables_from_spec')">show</a>)</span>
960
+ <div class="source" id="instance_variables_from_spec"><div class="CodeRay">
961
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/instance_variables_from</span><span style="color:#710">'</span></span>
962
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">InstanceVariablesFrom</span>
963
+
964
+
965
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">instance_variables_from</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
966
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">transforms the given parameter to instance variables when in it is a binding</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
967
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">example_method</span>(a = <span style="color:#00D;font-weight:bold">1</span>, b = <span style="color:#00D;font-weight:bold">2</span>)
968
+ instance_variables_from binding <span style="color:#888"># assigns @a and @b</span>
969
+ <span style="color:#080;font-weight:bold">end</span>
970
+
971
+ example_method
972
+ <span style="color:#33B">@a</span>.should == <span style="color:#00D;font-weight:bold">1</span>
973
+ <span style="color:#33B">@b</span>.should == <span style="color:#00D;font-weight:bold">2</span>
974
+ <span style="color:#080;font-weight:bold">end</span>
975
+
976
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">transforms the given parameter to instance variables when in it is a hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
977
+ params = { <span style="color:#808">c</span>: <span style="color:#00D;font-weight:bold">3</span>, <span style="color:#808">d</span>: <span style="color:#00D;font-weight:bold">4</span> }
978
+ instance_variables_from params
979
+
980
+ <span style="color:#33B">@c</span>.should == <span style="color:#00D;font-weight:bold">3</span>
981
+ <span style="color:#33B">@d</span>.should == <span style="color:#00D;font-weight:bold">4</span>
982
+ <span style="color:#080;font-weight:bold">end</span>
983
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
984
+ </div>
985
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_instance_variables_from_source">(<a href="javascript:show('instance_variables_from_source')">show</a>)</span>
986
+ <div class="source" id="instance_variables_from_source"><div class="CodeRay">
987
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
988
+
989
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
990
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">InstanceVariablesFrom</span>
991
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
992
+ private
993
+
994
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">instance_variables_from</span>(obj, *only)
995
+ iter =
996
+ <span style="color:#080;font-weight:bold">if</span> obj.is_a? <span style="color:#036;font-weight:bold">Binding</span>
997
+ obj.eval(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">local_variables</span><span style="color:#710">'</span></span>).map{|e| [obj.eval(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>e<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#710">&quot;</span></span>), e] }
998
+ <span style="color:#080;font-weight:bold">elsif</span> obj.is_a? <span style="color:#036;font-weight:bold">Hash</span>
999
+ obj.map{|k,v| [v,k] }
1000
+ <span style="color:#080;font-weight:bold">else</span>
1001
+ <span style="color:#888"># elsif obj.is_a? Enumerable</span>
1002
+ obj.each.with_index
1003
+ <span style="color:#080;font-weight:bold">end</span>
1004
+
1005
+ ret = []
1006
+ iter.each{ |value, arg|
1007
+ arg = arg.to_s
1008
+ <span style="color:#080;font-weight:bold">if</span> only.include?(arg) || only.include?(arg.to_sym) || only.empty?
1009
+ arg = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">_</span><span style="color:#710">'</span></span> + arg <span style="color:#080;font-weight:bold">if</span> (<span style="color:#00D;font-weight:bold">48</span>..<span style="color:#00D;font-weight:bold">57</span>).member? arg.unpack(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">C</span><span style="color:#710">'</span></span>)[<span style="color:#00D;font-weight:bold">0</span>] <span style="color:#888"># 1.8+1.9</span>
1010
+ ret &lt;&lt; ivar = <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#630">&quot;</span><span style="color:#A60">@</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>arg<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#630">&quot;</span></span>
1011
+ <span style="color:#038;font-weight:bold">self</span>.instance_variable_set ivar, value
1012
+ <span style="color:#080;font-weight:bold">end</span>
1013
+ }
1014
+ ret
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>
1018
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1019
+ </div>
1020
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/iterate'" id="iterate">iterate</h3>
1021
+ <table class="cube_table"
1022
+ id="iterate_cube"
1023
+ title="require 'zucker/iterate'"> <tr><th>Summary</th> <td>Iterate over one or more collections. It is like <code>.each</code> with two differences: It feels more like a control structure and you can easily iterate over multiple objects</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1024
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Iterate</span></pre></div>
1025
+ </div>
1026
+ </div></td></tr><tr><th>Usage</th> <td><h5>iterate</h5><div class="usage source" style="display:block"><div class="CodeRay">
1027
+ <div class="code"><pre>iterate [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>], [<span style="color:#00D;font-weight:bold">3</span>,<span style="color:#00D;font-weight:bold">4</span>,<span style="color:#00D;font-weight:bold">5</span>] <span style="color:#080;font-weight:bold">do</span> |e,f|
1028
+ puts <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>e<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="">,</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>f<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#710">&quot;</span></span>
1029
+ <span style="color:#080;font-weight:bold">end</span>
1030
+ <span style="color:#888"># outputs</span>
1031
+ <span style="color:#888"># 1,3</span>
1032
+ <span style="color:#888"># 2,4</span>
1033
+ <span style="color:#888"># ,5</span>
1034
+ </pre></div>
1035
+ </div>
1036
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_iterate_spec">(<a href="javascript:show('iterate_spec')">show</a>)</span>
1037
+ <div class="source" id="iterate_spec"><div class="CodeRay">
1038
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/iterate</span><span style="color:#710">'</span></span>
1039
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Iterate</span>
1040
+
1041
+
1042
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Object#iterate</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1043
+ let <span style="color:#A60">:a</span> <span style="color:#080;font-weight:bold">do</span> [<span style="color:#00D;font-weight:bold">1</span>, <span style="color:#00D;font-weight:bold">2</span>, <span style="color:#00D;font-weight:bold">3</span>] <span style="color:#080;font-weight:bold">end</span>
1044
+ let <span style="color:#A60">:b</span> <span style="color:#080;font-weight:bold">do</span> <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">%w|</span><span style="">a b c d</span><span style="color:#710">|</span></span> <span style="color:#080;font-weight:bold">end</span>
1045
+ let <span style="color:#A60">:res</span> <span style="color:#080;font-weight:bold">do</span> <span style="color:#036;font-weight:bold">Hash</span>.new {[]} <span style="color:#080;font-weight:bold">end</span>
1046
+
1047
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should behave like Enumerable#each for a single argument</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1048
+ iterate a <span style="color:#080;font-weight:bold">do</span> |ele|
1049
+ res[<span style="color:#A60">:iter</span>] &lt;&lt; ele
1050
+ <span style="color:#080;font-weight:bold">end</span>
1051
+
1052
+ a.each <span style="color:#080;font-weight:bold">do</span> |ele|
1053
+ res[<span style="color:#A60">:each</span>] &lt;&lt; ele
1054
+ <span style="color:#080;font-weight:bold">end</span>
1055
+
1056
+ res[<span style="color:#A60">:iter</span>].should == res[<span style="color:#A60">:each</span>]
1057
+ <span style="color:#080;font-weight:bold">end</span>
1058
+
1059
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should pass the right params to the block</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1060
+ res = <span style="color:#036;font-weight:bold">Hash</span>.new {[]} <span style="color:#888"># TODO: why?</span>
1061
+ res[<span style="color:#A60">:iter_a_b</span>] = [] <span style="color:#888"># ....</span>
1062
+ res[<span style="color:#A60">:iter_b_a</span>] = [] <span style="color:#888"># ....</span>
1063
+
1064
+
1065
+ iterate a, b <span style="color:#080;font-weight:bold">do</span> |e,f|
1066
+ res[<span style="color:#A60">:iter_a_b</span>] &lt;&lt; [e, f]
1067
+ <span style="color:#080;font-weight:bold">end</span>
1068
+
1069
+ res[<span style="color:#A60">:iter_a_b</span>].should == [
1070
+ [<span style="color:#00D;font-weight:bold">1</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>],
1071
+ [<span style="color:#00D;font-weight:bold">2</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">b</span><span style="color:#710">'</span></span>],
1072
+ [<span style="color:#00D;font-weight:bold">3</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">c</span><span style="color:#710">'</span></span>],
1073
+ [<span style="color:#038;font-weight:bold">nil</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">d</span><span style="color:#710">'</span></span>],
1074
+ ]
1075
+
1076
+ iterate b, a <span style="color:#080;font-weight:bold">do</span> |e,f|
1077
+ res[<span style="color:#A60">:iter_b_a</span>] &lt;&lt; [e, f]
1078
+ <span style="color:#080;font-weight:bold">end</span>
1079
+
1080
+ res[<span style="color:#A60">:iter_b_a</span>].should == [
1081
+ [<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>, <span style="color:#00D;font-weight:bold">1</span>],
1082
+ [<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">b</span><span style="color:#710">'</span></span>, <span style="color:#00D;font-weight:bold">2</span>],
1083
+ [<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">c</span><span style="color:#710">'</span></span>, <span style="color:#00D;font-weight:bold">3</span>],
1084
+ [<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">d</span><span style="color:#710">'</span></span>, <span style="color:#038;font-weight:bold">nil</span>],
1085
+ ]
1086
+
1087
+ <span style="color:#080;font-weight:bold">end</span>
1088
+
1089
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should return enumerators if no block is applied</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1090
+ res = <span style="color:#036;font-weight:bold">Hash</span>.new {[]} <span style="color:#888"># TODO: why?</span>
1091
+ res[<span style="color:#A60">:iter_a_b</span>] = [] <span style="color:#888"># ....</span>
1092
+ res[<span style="color:#A60">:iter_b_a</span>] = [] <span style="color:#888"># ....</span>
1093
+
1094
+ enumerator = iterate a,b
1095
+ enumerator.should be_kind_of(<span style="color:#036;font-weight:bold">RUBY_VERSION</span> &lt; <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">1.9</span><span style="color:#710">'</span></span> ? <span style="color:#036;font-weight:bold">Enumerable</span>::<span style="color:#036;font-weight:bold">Enumerator</span> : <span style="color:#036;font-weight:bold">Enumerator</span>)
1096
+ enumerator.to_a.should == [[<span style="color:#00D;font-weight:bold">1</span>,<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>], [<span style="color:#00D;font-weight:bold">2</span>,<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">b</span><span style="color:#710">'</span></span>], [<span style="color:#00D;font-weight:bold">3</span>,<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">c</span><span style="color:#710">'</span></span>], [<span style="color:#038;font-weight:bold">nil</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">d</span><span style="color:#710">'</span></span>]]
1097
+ <span style="color:#080;font-weight:bold">end</span>
1098
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1099
+ </div>
1100
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_iterate_source">(<a href="javascript:show('iterate_source')">show</a>)</span>
1101
+ <div class="source" id="iterate_source"><div class="CodeRay">
1102
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1103
+
1104
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1105
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Iterate</span>
1106
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
1107
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">iterate</span>(*params)
1108
+ <span style="color:#888"># params.shift.zip(*params).each{ |*elements| yield *elements }</span>
1109
+ raise <span style="color:#036;font-weight:bold">ArgumentError</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">wrong number of arguments (0)</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">if</span> params.empty?
1110
+
1111
+ first = params.shift
1112
+ <span style="color:#080;font-weight:bold">if</span> params.empty? <span style="color:#888"># single param - like each</span>
1113
+ <span style="color:#080;font-weight:bold">if</span> block_given?
1114
+ first.map{|e| <span style="color:#080;font-weight:bold">yield</span> e }
1115
+ <span style="color:#080;font-weight:bold">else</span>
1116
+ first.map.to_enum
1117
+ <span style="color:#080;font-weight:bold">end</span>
1118
+ <span style="color:#080;font-weight:bold">else</span> <span style="color:#888"># multiple params</span>
1119
+ max_size = [first, *params].max_by(&amp;<span style="color:#A60">:count</span>).size
1120
+ padded_first = first.to_a + [<span style="color:#038;font-weight:bold">nil</span>]*(max_size - first.count) <span style="color:#888"># append nils</span>
1121
+ obj = padded_first.zip(*params)
1122
+ <span style="color:#080;font-weight:bold">if</span> block_given?
1123
+ obj.map{|es| <span style="color:#080;font-weight:bold">yield</span>(*es) }
1124
+ <span style="color:#080;font-weight:bold">else</span>
1125
+ obj.map.to_enum
1126
+ <span style="color:#080;font-weight:bold">end</span>
1127
+ <span style="color:#080;font-weight:bold">end</span>
1128
+ <span style="color:#080;font-weight:bold">end</span>
1129
+ <span style="color:#080;font-weight:bold">end</span>
1130
+ <span style="color:#080;font-weight:bold">end</span>
1131
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1132
+ </div>
1133
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/marshal_copy'" id="marshal_copy">marshal_copy</h3>
1134
+ <table class="cube_table"
1135
+ id="marshal_copy_cube"
1136
+ title="require 'zucker/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">
1137
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">MarshalCopy</span></pre></div>
1138
+ </div>
1139
+ </div></td></tr><tr><th>Usage</th> <td><h5>Object#marshal_copy</h5><div class="usage source" style="display:block"><div class="CodeRay">
1140
+ <div class="code"><pre>a = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">%w[</span><span style="">hello world</span><span style="color:#710">]</span></span>
1141
+ b = a.mcopy
1142
+ </pre></div>
1143
+ </div>
1144
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_marshal_copy_spec">(<a href="javascript:show('marshal_copy_spec')">show</a>)</span>
1145
+ <div class="source" id="marshal_copy_spec"><div class="CodeRay">
1146
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/marshal_copy</span><span style="color:#710">'</span></span>
1147
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">MarshalCopy</span>
1148
+
1149
+
1150
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Object#marshal_copy</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1151
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">create a (deep) copy via marshalling</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1152
+ a = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">%w[</span><span style="">hello world</span><span style="color:#710">]</span></span>
1153
+ b = a.marshal_copy
1154
+ b.should == a
1155
+
1156
+ b[<span style="color:#00D;font-weight:bold">0</span>][<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">1</span>] = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="color:#710">'</span></span>
1157
+ b.should_not == a
1158
+ <span style="color:#080;font-weight:bold">end</span>
1159
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1160
+ </div>
1161
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_marshal_copy_source">(<a href="javascript:show('marshal_copy_source')">show</a>)</span>
1162
+ <div class="source" id="marshal_copy_source"><div class="CodeRay">
1163
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1164
+
1165
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1166
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">MarshalCopy</span>
1167
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
1168
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">marshal_copy</span>
1169
+ <span style="color:#036;font-weight:bold">Marshal</span>.load <span style="color:#036;font-weight:bold">Marshal</span>.dump <span style="color:#038;font-weight:bold">self</span>
1170
+ <span style="color:#080;font-weight:bold">end</span>
1171
+ <span style="color:#080;font-weight:bold">end</span>
1172
+ <span style="color:#080;font-weight:bold">end</span>
1173
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1174
+ </div>
1175
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/mash'" id="mash">mash</h3>
1176
+ <table class="cube_table"
1177
+ id="mash_cube"
1178
+ title="require 'zucker/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">
1179
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Mash</span></pre></div>
1180
+ </div>
1181
+ </div></td></tr><tr><th>Usage</th> <td><h5>Enumerable#mash</h5><div class="usage source" style="display:block"><div class="CodeRay">
1182
+ <div class="code"><pre>[<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>].mash{|e| [e, e.to_s] } <span style="color:#888"># =&gt; {1=&gt;'1',2=&gt;'2',3=&gt;'3'}</span></pre></div>
1183
+ </div>
1184
+ </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>
1185
+ <div class="source" id="mash_spec"><div class="CodeRay">
1186
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/mash</span><span style="color:#710">'</span></span>
1187
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Mash</span>
1188
+
1189
+
1190
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Array#mash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1191
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should &quot;map&quot; a hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1192
+ [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>].mash{|e| [e, e.to_s] }.should == {<span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">1</span><span style="color:#710">'</span></span>,<span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">2</span><span style="color:#710">'</span></span>,<span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">3</span><span style="color:#710">'</span></span>,}
1193
+ <span style="color:#080;font-weight:bold">end</span>
1194
+ <span style="color:#080;font-weight:bold">end</span>
1195
+
1196
+
1197
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Enumerator#mash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1198
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should &quot;map&quot; a hash</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1199
+ [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>,<span style="color:#00D;font-weight:bold">3</span>].each.mash{|e| [e, e.to_s] }.should == {<span style="color:#00D;font-weight:bold">1</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">1</span><span style="color:#710">'</span></span>,<span style="color:#00D;font-weight:bold">2</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">2</span><span style="color:#710">'</span></span>,<span style="color:#00D;font-weight:bold">3</span>=&gt;<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">3</span><span style="color:#710">'</span></span>,}
1200
+ <span style="color:#080;font-weight:bold">end</span>
1201
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1202
+ </div>
1203
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_mash_source">(<a href="javascript:show('mash_source')">show</a>)</span>
1204
+ <div class="source" id="mash_source"><div class="CodeRay">
1205
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1206
+
1207
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1208
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Mash</span>
1209
+ refine <span style="color:#036;font-weight:bold">Enumerator</span> <span style="color:#080;font-weight:bold">do</span>
1210
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">mash</span>
1211
+ ret = {}
1212
+ each{ |kv| ret.store( *(<span style="color:#080;font-weight:bold">yield</span>(kv)[<span style="color:#00D;font-weight:bold">0</span>,<span style="color:#00D;font-weight:bold">2</span>]) ) }
1213
+ ret
1214
+ <span style="color:#080;font-weight:bold">end</span>
1215
+ <span style="color:#080;font-weight:bold">end</span>
1216
+
1217
+ refine <span style="color:#036;font-weight:bold">Array</span> <span style="color:#080;font-weight:bold">do</span>
1218
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">mash</span>
1219
+ ret = {}
1220
+ each{ |kv| ret.store( *(<span style="color:#080;font-weight:bold">yield</span>(kv)[<span style="color:#00D;font-weight:bold">0</span>,<span style="color:#00D;font-weight:bold">2</span>]) ) }
1221
+ ret
1222
+ <span style="color:#080;font-weight:bold">end</span>
1223
+ <span style="color:#080;font-weight:bold">end</span>
1224
+ <span style="color:#080;font-weight:bold">end</span>
1225
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1226
+ </div>
1227
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/regexp_union'" id="regexp_union">regexp_union</h3>
1228
+ <table class="cube_table"
1229
+ id="regexp_union_cube"
1230
+ title="require 'zucker/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">
1231
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">RegexpUnion</span></pre></div>
1232
+ </div>
1233
+ </div></td></tr><tr><th>Usage</th> <td><h5>Regexp#|, String#|</h5><div class="usage source" style="display:block"><div class="CodeRay">
1234
+ <div class="code"><pre><span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span> | <span style="background-color:#fff0ff"><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:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">cheat</span><span style="color:#710">&quot;</span></span>
1235
+ <span style="color:#888"># creates a Regexp similar to:</span>
1236
+ <span style="color:#888"># /(Ruby\d|[tT][eE][sS][tT]|cheat)/</span>
1237
+ </pre></div>
1238
+ </div>
1239
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_regexp_union_spec">(<a href="javascript:show('regexp_union_spec')">show</a>)</span>
1240
+ <div class="source" id="regexp_union_spec"><div class="CodeRay">
1241
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/regexp_union</span><span style="color:#710">'</span></span>
1242
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">RegexpUnion</span>
1243
+
1244
+
1245
+ shared_examples_for <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">Regexp.union operator</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1246
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">creates a Regexp.union of both operands</span><span style="color:#710">&quot;</span></span> <span style="color:#080;font-weight:bold">do</span>
1247
+ (<span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span> | <span style="background-color:#fff0ff"><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:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">cheat</span><span style="color:#710">&quot;</span></span>).should ==
1248
+ <span style="color:#036;font-weight:bold">Regexp</span>.union( <span style="color:#036;font-weight:bold">Regexp</span>.union( <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#808">Ruby</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span>, <span style="background-color:#fff0ff"><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:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">cheat</span><span style="color:#710">&quot;</span></span> )
1249
+ <span style="color:#080;font-weight:bold">end</span>
1250
+ <span style="color:#080;font-weight:bold">end</span>
1251
+
1252
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Regexp#|</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1253
+ it_should_behave_like <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Regexp.union operator</span><span style="color:#710">'</span></span>
1254
+ <span style="color:#080;font-weight:bold">end</span>
1255
+
1256
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#|</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1257
+ it_should_behave_like <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Regexp.union operator</span><span style="color:#710">'</span></span>
1258
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1259
+ </div>
1260
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_regexp_union_source">(<a href="javascript:show('regexp_union_source')">show</a>)</span>
1261
+ <div class="source" id="regexp_union_source"><div class="CodeRay">
1262
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1263
+
1264
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1265
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">RegexpUnion</span>
1266
+ refine <span style="color:#036;font-weight:bold">Regexp</span> <span style="color:#080;font-weight:bold">do</span>
1267
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">|</span>(arg)
1268
+ <span style="color:#036;font-weight:bold">Regexp</span>.union <span style="color:#038;font-weight:bold">self</span>, arg.is_a?(<span style="color:#036;font-weight:bold">Regexp</span>) ? arg : arg.to_s
1269
+ <span style="color:#080;font-weight:bold">end</span>
1270
+ <span style="color:#080;font-weight:bold">end</span>
1271
+
1272
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1273
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">|</span>(arg)
1274
+ <span style="color:#036;font-weight:bold">Regexp</span>.union <span style="color:#038;font-weight:bold">self</span>, arg.is_a?(<span style="color:#036;font-weight:bold">Regexp</span>) ? arg : arg.to_s
1275
+ <span style="color:#080;font-weight:bold">end</span>
1276
+ <span style="color:#080;font-weight:bold">end</span>
1277
+ <span style="color:#080;font-weight:bold">end</span>
1278
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1279
+ </div>
1280
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/square_brackets_for'" id="square_brackets_for">square_brackets_for</h3>
1281
+ <table class="cube_table"
1282
+ id="square_brackets_for_cube"
1283
+ title="require 'zucker/square_brackets_for'"> <tr><th>Summary</th> <td>This helper methods defines <code>[]</code> and <code>[]=</code> for accesing an instance variable</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1284
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">SquareBracketsFor</span></pre></div>
1285
+ </div>
1286
+ </div></td></tr><tr><th>Usage</th> <td><h5>square_brackets_for</h5><div class="usage source" style="display:block"><div class="CodeRay">
1287
+ <div class="code"><pre><span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Klass</span>
1288
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">initialize</span>
1289
+ <span style="color:#33B">@var</span> = {
1290
+ <span style="color:#A60">:a_key</span> =&gt; <span style="color:#00D;font-weight:bold">1</span>,
1291
+ <span style="color:#A60">:another_one</span> =&gt; <span style="color:#00D;font-weight:bold">2</span>,
1292
+ }
1293
+ <span style="color:#080;font-weight:bold">end</span>
1294
+
1295
+ square_brackets_for <span style="color:#A60">:var</span> <span style="color:#888"># creates [] and []=</span>
1296
+ <span style="color:#888"># square_brackets_for :var, false # would create only []</span>
1297
+ <span style="color:#080;font-weight:bold">end</span>
1298
+
1299
+ a = <span style="color:#036;font-weight:bold">Klass</span>.new
1300
+ a[<span style="color:#A60">:a_key</span>] <span style="color:#888"># =&gt; 1</span>
1301
+ </pre></div>
1302
+ </div>
1303
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_square_brackets_for_spec">(<a href="javascript:show('square_brackets_for_spec')">show</a>)</span>
1304
+ <div class="source" id="square_brackets_for_spec"><div class="CodeRay">
1305
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/square_brackets_for</span><span style="color:#710">'</span></span>
1306
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">SquareBracketsFor</span>
1307
+
1308
+
1309
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">square_brackets_for</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1310
+ before <span style="color:#080;font-weight:bold">do</span>
1311
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Klass</span>
1312
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">initialize</span>
1313
+ <span style="color:#33B">@var</span> = { <span style="color:#808">a_key</span>: <span style="color:#00D;font-weight:bold">1</span>, <span style="color:#808">another_one</span>: <span style="color:#00D;font-weight:bold">2</span> }
1314
+ <span style="color:#080;font-weight:bold">end</span>
1315
+
1316
+ <span style="color:#33B">@eigenvar</span> = { <span style="color:#808">a_key</span>: <span style="color:#00D;font-weight:bold">99</span> }
1317
+ <span style="color:#080;font-weight:bold">end</span>
1318
+ <span style="color:#080;font-weight:bold">end</span>
1319
+
1320
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should define a [] getter (not a setter) for an instance var, if the second parameter is false</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1321
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Klass</span>
1322
+ square_brackets_for <span style="color:#A60">:var</span>, <span style="color:#038;font-weight:bold">nil</span>
1323
+ <span style="color:#080;font-weight:bold">end</span>
1324
+
1325
+ a = <span style="color:#036;font-weight:bold">Klass</span>.new
1326
+ a[<span style="color:#A60">:a_key</span>].should == <span style="color:#00D;font-weight:bold">1</span>
1327
+
1328
+ proc <span style="color:#080;font-weight:bold">do</span>
1329
+ a[<span style="color:#A60">:this_is</span>] = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">not possible</span><span style="color:#710">'</span></span>
1330
+ <span style="color:#080;font-weight:bold">end</span>.should raise_exception <span style="color:#036;font-weight:bold">NoMethodError</span>
1331
+ <span style="color:#080;font-weight:bold">end</span>
1332
+
1333
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should define [] and []= for accessing an instance variable</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1334
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Klass</span>
1335
+ square_brackets_for <span style="color:#A60">:var</span>
1336
+ <span style="color:#080;font-weight:bold">end</span>
1337
+
1338
+ a = <span style="color:#036;font-weight:bold">Klass</span>.new
1339
+ a[<span style="color:#A60">:a_key</span>].should == <span style="color:#00D;font-weight:bold">1</span>
1340
+
1341
+ a[<span style="color:#A60">:this_is</span>] = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">useful</span><span style="color:#710">'</span></span>
1342
+ a[<span style="color:#A60">:this_is</span>].should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">useful</span><span style="color:#710">'</span></span>
1343
+ <span style="color:#080;font-weight:bold">end</span>
1344
+
1345
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should also work for class-instance variables</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1346
+ <span style="color:#080;font-weight:bold">class</span> <span style="color:#B06;font-weight:bold">Klass</span>
1347
+ <span style="color:#080;font-weight:bold">class</span> &lt;&lt; <span style="color:#B06;font-weight:bold">Klass</span>
1348
+ square_brackets_for <span style="color:#A60">:eigenvar</span>
1349
+ <span style="color:#080;font-weight:bold">end</span>
1350
+ <span style="color:#080;font-weight:bold">end</span>
1351
+
1352
+ <span style="color:#036;font-weight:bold">Klass</span>[<span style="color:#A60">:a_key</span>].should == <span style="color:#00D;font-weight:bold">99</span>
1353
+ <span style="color:#080;font-weight:bold">end</span>
1354
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1355
+ </div>
1356
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_square_brackets_for_source">(<a href="javascript:show('square_brackets_for_source')">show</a>)</span>
1357
+ <div class="source" id="square_brackets_for_source"><div class="CodeRay">
1358
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1359
+
1360
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1361
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">SquareBracketsFor</span>
1362
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
1363
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">square_brackets_for</span>(ivar, assignment = <span style="color:#038;font-weight:bold">true</span>)
1364
+ define_method <span style="color:#A60">:[]</span> <span style="color:#080;font-weight:bold">do</span> |key|
1365
+ (instance_variable_get <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#630">&quot;</span><span style="color:#A60">@</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>ivar<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#630">&quot;</span></span>)[key]
1366
+ <span style="color:#080;font-weight:bold">end</span>
1367
+
1368
+ <span style="color:#080;font-weight:bold">if</span> assignment
1369
+ define_method <span style="color:#A60">:[]=</span> <span style="color:#080;font-weight:bold">do</span> |key, value|
1370
+ (instance_variable_get <span style="color:#A60"><span style="color:#A60">:</span><span style="color:#630">&quot;</span><span style="color:#A60">@</span><span style="background:#ddd;color:black"><span style="background:#ddd;font-weight:bold;color:#666">#{</span>ivar<span style="background:#ddd;font-weight:bold;color:#666">}</span></span><span style="color:#630">&quot;</span></span>)[key] = value
1371
+ <span style="color:#080;font-weight:bold">end</span>
1372
+ <span style="color:#080;font-weight:bold">end</span>
1373
+ <span style="color:#080;font-weight:bold">end</span>
1374
+ <span style="color:#080;font-weight:bold">end</span>
1375
+ <span style="color:#080;font-weight:bold">end</span>
1376
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1377
+ </div>
1378
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/string_extras'" id="string_extras">string_extras</h3>
1379
+ <table class="cube_table"
1380
+ id="string_extras_cube"
1381
+ title="require 'zucker/string_extras'"> <tr><th>Summary</th> <td>Generic <code>String</code> extensions. Strings cannot be comfortable enough!</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1382
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">StringExtras</span></pre></div>
1383
+ </div>
1384
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#lchomp</h5><div class="usage source" style="display:block"><div class="CodeRay">
1385
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style=""> Yes</span><span style="color:#710">'</span></span>.lchomp <span style="color:#888"># =&gt; ' Yes'</span></pre></div>
1386
+ </div>
1387
+ </div><h5>String#lchomp!</h5><div class="usage source" style="display:block"><div class="CodeRay">
1388
+ <div class="code"><pre><span style="color:#888"># mutable lchomp version</span></pre></div>
1389
+ </div>
1390
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_string_extras_spec">(<a href="javascript:show('string_extras_spec')">show</a>)</span>
1391
+ <div class="source" id="string_extras_spec"><div class="CodeRay">
1392
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/string_extras</span><span style="color:#710">'</span></span>
1393
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">StringExtras</span>
1394
+
1395
+ describe <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1396
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#lchomp</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1397
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should chomp on the left side</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1398
+ string = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ameise</span><span style="color:#710">'</span></span>
1399
+ expect( string.lchomp(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>) ).to eq <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">meise</span><span style="color:#710">'</span></span>
1400
+ expect( string ).to eq <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ameise</span><span style="color:#710">'</span></span>
1401
+ <span style="color:#080;font-weight:bold">end</span>
1402
+ <span style="color:#080;font-weight:bold">end</span>
1403
+
1404
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#lchomp!</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1405
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should chomp on the left side (mutating)</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1406
+ string = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ameise</span><span style="color:#710">'</span></span>
1407
+ expect( string.lchomp!(<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">a</span><span style="color:#710">'</span></span>) ).to eq <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">meise</span><span style="color:#710">'</span></span>
1408
+ expect( string ).to eq <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">meise</span><span style="color:#710">'</span></span>
1409
+ <span style="color:#080;font-weight:bold">end</span>
1410
+ <span style="color:#080;font-weight:bold">end</span>
1411
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1412
+ </div>
1413
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_string_extras_source">(<a href="javascript:show('string_extras_source')">show</a>)</span>
1414
+ <div class="source" id="string_extras_source"><div class="CodeRay">
1415
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1416
+
1417
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1418
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">StringExtras</span>
1419
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1420
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">lchomp</span>(arg = <span style="color:#d70;font-weight:bold">$/</span>)
1421
+ reverse.chomp(arg).reverse
1422
+ <span style="color:#080;font-weight:bold">end</span>
1423
+
1424
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">lchomp!</span>(arg = <span style="color:#d70;font-weight:bold">$/</span>)
1425
+ replace reverse.chomp(arg).reverse
1426
+ <span style="color:#080;font-weight:bold">end</span>
1427
+ <span style="color:#080;font-weight:bold">end</span>
1428
+ <span style="color:#080;font-weight:bold">end</span>
1429
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1430
+ </div>
1431
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/string_op'" id="string_op">string_op</h3>
1432
+ <table class="cube_table"
1433
+ id="string_op_cube"
1434
+ title="require 'zucker/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">
1435
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">StringOp</span></pre></div>
1436
+ </div>
1437
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#-</h5><div class="usage source" style="display:block"><div class="CodeRay">
1438
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">1234abc5678</span><span style="color:#710">'</span></span> - <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">b</span><span style="color:#710">'</span></span> - <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span> <span style="color:#888"># =&gt; ac</span></pre></div>
1439
+ </div>
1440
+ </div><h5>String#^</h5><div class="usage source" style="display:block"><div class="CodeRay">
1441
+ <div class="code"><pre><span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Yes vs No</span><span style="color:#710">'</span></span>^<span style="color:#00D;font-weight:bold">2</span> <span style="color:#888"># =&gt; 's vs No'</span></pre></div>
1442
+ </div>
1443
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_string_op_spec">(<a href="javascript:show('string_op_spec')">show</a>)</span>
1444
+ <div class="source" id="string_op_spec"><div class="CodeRay">
1445
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/string_op</span><span style="color:#710">'</span></span>
1446
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">StringOp</span>
1447
+
1448
+
1449
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#-</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1450
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">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>
1451
+ (<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">1234abc5678</span><span style="color:#710">'</span></span> - <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">b</span><span style="color:#710">'</span></span> - <span style="background-color:#fff0ff"><span style="color:#404">/</span><span style="color:#04D">\d</span><span style="color:#404">/</span></span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">ac</span><span style="color:#710">'</span></span>
1452
+ <span style="color:#080;font-weight:bold">end</span>
1453
+ <span style="color:#080;font-weight:bold">end</span>
1454
+
1455
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">String#^</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1456
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should give C-like substring access to strings</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1457
+ string = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Theoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1458
+
1459
+ (string^<span style="color:#00D;font-weight:bold">0</span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Theoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1460
+ (string^<span style="color:#00D;font-weight:bold">1</span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">heoretische Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1461
+ (string^<span style="color:#00D;font-weight:bold">13</span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Informatik ist voll geil!</span><span style="color:#710">'</span></span>
1462
+ (string^<span style="color:#00D;font-weight:bold">-1</span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">Theoretische Informatik ist voll geil</span><span style="color:#710">'</span></span>
1463
+ (string^<span style="color:#00D;font-weight:bold">38</span>).should == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="color:#710">'</span></span>
1464
+ (string^<span style="color:#00D;font-weight:bold">99</span>).should == <span style="color:#038;font-weight:bold">nil</span>
1465
+ <span style="color:#080;font-weight:bold">end</span>
1466
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1467
+ </div>
1468
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_string_op_source">(<a href="javascript:show('string_op_source')">show</a>)</span>
1469
+ <div class="source" id="string_op_source"><div class="CodeRay">
1470
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1471
+
1472
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1473
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">StringOp</span>
1474
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1475
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">-</span>(rem)
1476
+ gsub( <span style="color:#036;font-weight:bold">Regexp</span> === rem ? rem : rem.to_s, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="color:#710">'</span></span> )
1477
+ <span style="color:#080;font-weight:bold">end</span>
1478
+
1479
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">^</span>(pos)
1480
+ pos = pos.to_i
1481
+ <span style="color:#080;font-weight:bold">if</span> pos &gt;= <span style="color:#00D;font-weight:bold">0</span>
1482
+ <span style="color:#038;font-weight:bold">self</span>[pos..<span style="color:#00D;font-weight:bold">-1</span>]
1483
+ <span style="color:#080;font-weight:bold">else</span>
1484
+ <span style="color:#038;font-weight:bold">self</span>[<span style="color:#00D;font-weight:bold">0</span>...pos]
1485
+ <span style="color:#080;font-weight:bold">end</span>
1486
+ <span style="color:#080;font-weight:bold">end</span>
1487
+ <span style="color:#080;font-weight:bold">end</span>
1488
+ <span style="color:#080;font-weight:bold">end</span>
1489
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1490
+ </div>
1491
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/tap'" id="tap">tap</h3>
1492
+ <table class="cube_table"
1493
+ id="tap_cube"
1494
+ title="require 'zucker/tap'"> <tr><th>Summary</th> <td>Adds the two <code>tap</code> variants <code>tap_on</code> (formerly known as <code>returning</code> in ActiveSupport) and <code>make_new</code></td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1495
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Tap</span></pre></div>
1496
+ </div>
1497
+ </div></td></tr><tr><th>Usage</th> <td><h5>tap_on</h5><div class="usage source" style="display:block"><div class="CodeRay">
1498
+ <div class="code"><pre>tap_on [<span style="color:#00D;font-weight:bold">1</span>,<span style="color:#00D;font-weight:bold">2</span>] <span style="color:#080;font-weight:bold">do</span> |obj|
1499
+ obj[<span style="color:#00D;font-weight:bold">4</span>] = <span style="color:#00D;font-weight:bold">5</span>
1500
+ <span style="color:#080;font-weight:bold">end</span> <span style="color:#888">#=&gt; [1, 2, nil, nil, 5]</span>
1501
+ </pre></div>
1502
+ </div>
1503
+ </div><h5>make_new</h5><div class="usage source" style="display:block"><div class="CodeRay">
1504
+ <div class="code"><pre>make_new <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span> |obj|
1505
+ obj[<span style="color:#00D;font-weight:bold">1</span>] = <span style="color:#00D;font-weight:bold">2</span>
1506
+ <span style="color:#080;font-weight:bold">end</span> <span style="color:#888">#=&gt; {1 =&gt; 2}</span>
1507
+ </pre></div>
1508
+ </div>
1509
+ </div></td></tr><tr><th>Information</th> <td>Read more about using tap on the <a href="http://blog.rubybestpractices.com/posts/gregory/011-tap-that-hash.html">ruby best practices</a> blog.</td></tr><tr><th>Specification</th> <td> <span id="show_tap_spec">(<a href="javascript:show('tap_spec')">show</a>)</span>
1510
+ <div class="source" id="tap_spec"><div class="CodeRay">
1511
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/tap</span><span style="color:#710">'</span></span>
1512
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">Tap</span>
1513
+
1514
+
1515
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">tap_on</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1516
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should call tap on the argument and apply the block</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1517
+ obj = <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">&quot;</span><span style="">an_object</span><span style="color:#710">&quot;</span></span>
1518
+ block = <span style="color:#A60">:reverse</span>.to_proc
1519
+
1520
+ tap_on( obj, &amp;block ).should == obj.tap( &amp;block )
1521
+ <span style="color:#080;font-weight:bold">end</span>
1522
+ <span style="color:#080;font-weight:bold">end</span>
1523
+
1524
+ describe <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">make_new</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1525
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should create a new instance of the class given as argument, apply the block on it and return result</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1526
+ make_new <span style="color:#036;font-weight:bold">Hash</span> <span style="color:#080;font-weight:bold">do</span> |obj|
1527
+ obj[<span style="color:#00D;font-weight:bold">1</span>] = <span style="color:#00D;font-weight:bold">2</span>
1528
+ <span style="color:#080;font-weight:bold">end</span>.should.send(<span style="color:#A60"><span style="color:#A60">:</span><span style="color:#630">'</span><span style="color:#A60">==</span><span style="color:#630">'</span></span>, { <span style="color:#00D;font-weight:bold">1</span> =&gt; <span style="color:#00D;font-weight:bold">2</span>})
1529
+ <span style="color:#080;font-weight:bold">end</span>
1530
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1531
+ </div>
1532
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_tap_source">(<a href="javascript:show('tap_source')">show</a>)</span>
1533
+ <div class="source" id="tap_source"><div class="CodeRay">
1534
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1535
+
1536
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1537
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Tap</span>
1538
+ refine <span style="color:#036;font-weight:bold">Object</span> <span style="color:#080;font-weight:bold">do</span>
1539
+ private
1540
+
1541
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">tap_on</span>(obj, &amp;block)
1542
+ obj.tap(&amp;block)
1543
+ <span style="color:#080;font-weight:bold">end</span>
1544
+
1545
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">make_new</span>(what, *args, &amp;block)
1546
+ what.new(*args).tap(&amp;block)
1547
+ <span style="color:#080;font-weight:bold">end</span>
1548
+ <span style="color:#080;font-weight:bold">end</span>
1549
+ <span style="color:#080;font-weight:bold">end</span>
1550
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1551
+ </div>
1552
+ </div> </td></tr></table></div> <div class="cubes"><h3 title="require 'zucker/unary_conversion'" id="unary_conversion">unary_conversion</h3>
1553
+ <table class="cube_table"
1554
+ id="unary_conversion_cube"
1555
+ title="require 'zucker/unary_conversion'"> <tr><th>Summary</th> <td>Easy conversion between strings and symbols. Sometimes, you do not care if you get a <code>String</code> or <code>Symbol</code> as input. Instead of using AS' HashWithIndifferentAccess you can just always convert to your preferred format</td></tr><tr><th>Activate</th> <td><div class="using source" style="display:block"><div class="CodeRay">
1556
+ <div class="code"><pre>using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">UnaryConversion</span></pre></div>
1557
+ </div>
1558
+ </div></td></tr><tr><th>Usage</th> <td><h5>String#+@</h5><div class="usage source" style="display:block"><div class="CodeRay">
1559
+ <div class="code"><pre>+<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">was_string</span><span style="color:#710">'</span></span> <span style="color:#888"># =&gt; 'was_string'</span></pre></div>
1560
+ </div>
1561
+ </div><h5>String#-@</h5><div class="usage source" style="display:block"><div class="CodeRay">
1562
+ <div class="code"><pre>-<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">was_string</span><span style="color:#710">'</span></span> <span style="color:#888"># =&gt; :was_string</span></pre></div>
1563
+ </div>
1564
+ </div><h5>Symbol#+@</h5><div class="usage source" style="display:block"><div class="CodeRay">
1565
+ <div class="code"><pre>+<span style="color:#A60">:was_symbol</span> <span style="color:#888"># =&gt; 'was_symbol'</span></pre></div>
1566
+ </div>
1567
+ </div><h5>Symbol#-@</h5><div class="usage source" style="display:block"><div class="CodeRay">
1568
+ <div class="code"><pre>-<span style="color:#A60">:was_symbol</span> <span style="color:#888"># =&gt; :was_symbol</span></pre></div>
1569
+ </div>
1570
+ </div></td></tr><tr><th>Specification</th> <td> <span id="show_unary_conversion_spec">(<a href="javascript:show('unary_conversion_spec')">show</a>)</span>
1571
+ <div class="source" id="unary_conversion_spec"><div class="CodeRay">
1572
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker/unary_conversion</span><span style="color:#710">'</span></span>
1573
+ using <span style="color:#036;font-weight:bold">Zucker</span>::<span style="color:#036;font-weight:bold">UnaryConversion</span>
1574
+
1575
+
1576
+ describe <span style="color:#036;font-weight:bold">Symbol</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#+@</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1577
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should convert to_s</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1578
+ +<span style="color:#A60">:matz</span> == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">matz</span><span style="color:#710">'</span></span>
1579
+ <span style="color:#080;font-weight:bold">end</span>
1580
+ <span style="color:#080;font-weight:bold">end</span>
1581
+
1582
+ describe <span style="color:#036;font-weight:bold">Symbol</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#-@</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1583
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should do nothing</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1584
+ -<span style="color:#A60">:matz</span> == <span style="color:#A60">:matz</span>
1585
+ <span style="color:#080;font-weight:bold">end</span>
1586
+ <span style="color:#080;font-weight:bold">end</span>
1587
+
1588
+ describe <span style="color:#036;font-weight:bold">String</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#+@</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1589
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should do nothing</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1590
+ +<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">matz</span><span style="color:#710">'</span></span> == <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">matz</span><span style="color:#710">'</span></span>
1591
+ <span style="color:#080;font-weight:bold">end</span>
1592
+ <span style="color:#080;font-weight:bold">end</span>
1593
+
1594
+ describe <span style="color:#036;font-weight:bold">String</span>, <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">#-@</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1595
+ it <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">should convert to_sym</span><span style="color:#710">'</span></span> <span style="color:#080;font-weight:bold">do</span>
1596
+ -<span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">matz</span><span style="color:#710">'</span></span> == <span style="color:#A60">:matz</span>
1597
+ <span style="color:#080;font-weight:bold">end</span>
1598
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1599
+ </div>
1600
+ </div> </td></tr><tr><th>Source</th> <td> <span id="show_unary_conversion_source">(<a href="javascript:show('unary_conversion_source')">show</a>)</span>
1601
+ <div class="source" id="unary_conversion_source"><div class="CodeRay">
1602
+ <div class="code"><pre>require <span style="background-color:#fff0f0;color:#D20"><span style="color:#710">'</span><span style="">zucker</span><span style="color:#710">'</span></span>
1603
+
1604
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">Zucker</span>
1605
+ <span style="color:#080;font-weight:bold">module</span> <span style="color:#B06;font-weight:bold">UnaryConversion</span>
1606
+ refine <span style="color:#036;font-weight:bold">String</span> <span style="color:#080;font-weight:bold">do</span>
1607
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">+@</span>
1608
+ <span style="color:#038;font-weight:bold">self</span>
1609
+ <span style="color:#080;font-weight:bold">end</span>
1610
+
1611
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">-@</span>
1612
+ to_sym
1613
+ <span style="color:#080;font-weight:bold">end</span>
1614
+ <span style="color:#080;font-weight:bold">end</span>
1615
+
1616
+ refine <span style="color:#036;font-weight:bold">Symbol</span> <span style="color:#080;font-weight:bold">do</span>
1617
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">+@</span>
1618
+ to_s
1619
+ <span style="color:#080;font-weight:bold">end</span>
1620
+
1621
+ <span style="color:#080;font-weight:bold">def</span> <span style="color:#06B;font-weight:bold">-@</span>
1622
+ <span style="color:#038;font-weight:bold">self</span>
1623
+ <span style="color:#080;font-weight:bold">end</span>
1624
+ <span style="color:#080;font-weight:bold">end</span>
1625
+ <span style="color:#080;font-weight:bold">end</span>
1626
+ <span style="color:#080;font-weight:bold">end</span></pre></div>
1627
+ </div>
1628
+ </div> </td></tr></table></div>
1629
+
1630
+ <h2>Changelog</h2>
1631
+ <div class="cubes">
1632
+ <pre class="scode">2014-04-01 | <a href="http://rubyzucker.info/100/">Zucker 100</a>.0
1633
+ * drop Ruby 1.8 support
1634
+ * rewrite zucker to use refinements!
1635
+ * use usual semantic versioning
1636
+ * remove all "debug" cubes, use the "debugging" gem instead!
1637
+ * remove "ruby_version" cube, use the "ruby_version" gem instead!
1638
+ * remove "engine" cube, use the "ruby_engine" gem instead!
1639
+ * remove "info" cube, use the "ruby_info" gem instead!
1640
+ * remove "os" cube, use rdp's "os" gem instead!
1641
+ * remove "*_to_proc" cubes, use the "procstar" gem instead!
1642
+ * remove "sandbox" cube, since sandboxing is not recommended and removed from Ruby 2.1
1643
+ * remove "kernel" and "not" cube completely
1644
+ * tweaks to most other cubes
1645
+
1646
+
1647
+ 2013-04-30 | <a href="http://rubyzucker.info/13/">Zucker 13</a>
1648
+ * fix alias_for bug
1649
+ * let RubyVersion#inspect and RubyEngine#inspect map to #to_s
1650
+ * remove Array#sum
1651
+ * repackage (gh#4)
1652
+
1653
+
1654
+ 2012-01-16 | <a href="http://rubyzucker.info/12/">Zucker 12</a>
1655
+ * fix a requiring bug
1656
+ * rename zucker/version cube to zucker/ruby_version and Zucker::PACKAGES to Zucker::PACKS
1657
+ * remove more_aliases! (keep it simple...)
1658
+ * add case cube: String#to_camel and String#to_snake
1659
+
1660
+
1661
+ 2011-05-25 | <a href="http://rubyzucker.info/11/">Zucker 11</a>
1662
+ * add Zucker::constants to check if cube has been required (e.g. Zucker::AliasFor if 'zucker/alias_for' is loaded)
1663
+ * rbx tweaks
1664
+ * don't define Binding#vars on rbx (prevent endless recursion)
1665
+ * sandbox-not-working warning
1666
+ * add Kernel#ignore_sigquit!
1667
+ * fix warnings
1668
+ * doc tweaks
1669
+
1670
+
1671
+ 2011-04-29 | <a href="http://rubyzucker.info/10/">Zucker 10</a>
1672
+ * doc/spec tweaks
1673
+ * make test.rubygems.org-testable
1674
+ * fix zucker 9 permission issue
1675
+
1676
+
1677
+ 2011-01-22 | <a href="http://rubyzucker.info/9/">Zucker 9</a>
1678
+ * remove history versions (sorry, it caused too much gem/rdoc troubles)
1679
+ * add file cube: File.delete! and File.gsub
1680
+ * debug pack improvements
1681
+ * binding: typos + return nil
1682
+ * cc: support for ripl + return nil
1683
+ * mm: also show eigenclass for modules + nicer displaying + return nil
1684
+ * added Regexp#visualize
1685
+ * remove optional sandbox param
1686
+ * rename xxx2proc to xxx_to_proc
1687
+ * change rakefile/rspec/gemspec structure
1688
+ * more minor fixes and improvements
1689
+
1690
+
1691
+ 2010-10-06 | <a href="http://rubyzucker.info/8/">Zucker 8</a>
1692
+ * fix a little alias_for bug
1693
+ * disable rdoc creation when installing (in favour of the custom docs)
1694
+ * change Binding#inspect to Binding.variables (was too verbose and dangerous)
1695
+
1696
+
1697
+ 2010-10-03 | <a href="http://rubyzucker.info/7/">Zucker 7</a>
1698
+ * fix critical OS.windows? bug
1699
+
1700
+
1701
+ 2010-10-03 | <a href="http://rubyzucker.info/6/">Zucker 6</a>
1702
+ * no new cubes
1703
+ * bugfix for OS.posix?
1704
+ * small changes + bugfixes + doc improvements
1705
+ * add two user methods to Info
1706
+ * change egonil semantics ( using method_missing, see http://rbjl.net/26/catch_nil.rb )
1707
+ * bugfix for vv
1708
+
1709
+
1710
+ 2010-09-04 | <a href="http://rubyzucker.info/5/">Zucker 5</a>
1711
+ * debug edition - add two debug helpers: oo (output line, method, file) and cc (output method callstack)
1712
+ * rename cube D to dd add add more debug aliases (for mm and binding)
1713
+ * fix __SPECIAL_VARS__ in info and kernel cube and some minor bugfixes
1714
+ * Zucker.activate_more_aliases! option
1715
+ * add Hash#&amp;
1716
+ * add aliases: File.filename (for basename), Dir.join and Dir.split (for File.join, split)
1717
+ * add a flexible requiring mechansim in zucker.rb (no api changes)
1718
+ * restructure packages
1719
+ * add rake tasks for releasing
1720
+ * improve RubyVersion constant (cleaner and more flexible)
1721
+
1722
+
1723
+ 2010-09-01 | <a href="http://rubyzucker.info/4/">Zucker 4</a>
1724
+ * fix Binding#inspect
1725
+ * add RubyEngine constant
1726
+ * add RubyVersion constant
1727
+ * add OS constant
1728
+ * add q debug method (like p but on one line)
1729
+ * add String#-
1730
+
1731
+
1732
+ 2010-08-14 | <a href="http://rubyzucker.info/3/">Zucker 3</a>
1733
+ * add tap cube
1734
+ * add Object#not
1735
+ * add alias_for for an alternative alias syntax
1736
+ * add String#constantize (improved AS version)
1737
+ * improve Info module
1738
+ * make Array#sum Rails compatibile
1739
+ * improve docs
1740
+ * change directory layout (no changes for requiring)
1741
+ * more small changes
1742
+
1743
+
1744
+ 2010-08-08 | <a href="http://rubyzucker.info/2/">Zucker 2</a>
1745
+ * add info cube
1746
+ * add chaining for array2proc
1747
+ * fix Hash.zip
1748
+ * fix instance_variables_from binding for 1.9
1749
+ * more specs
1750
+
1751
+
1752
+ 2010-08-06 | <a href="http://rubyzucker.info/1/">Zucker 1</a>
1753
+ * initial release
1754
+
1755
+
1756
+ 2010-08-05 | <a href="http://rubyzucker.info/rubyzucker.pdf">Zucker 0</a>
1757
+ * pre-release for rug-b talk
1758
+
1759
+ </pre>
1760
+ </div>
1761
+ <br/>
1762
+ </div>
1763
+
1764
+ <div id="foot">
1765
+ <div id="smile"><a href="http://janlelis.de">J-_-L</a></div>
1766
+ This is the Ruby Zucker 100.0.0 documentation (2014-04-01).
1767
+ The current documentation is always available at <a href="http://rubyzucker.info">rubyzucker.info</a>.
1768
+ Source at <a href="https://github.com/janlelis/zucker">github</a>.
1769
+ Ruby Logo CC-BY-SA Yukihiro Matsumoto.
1770
+ </div>
1771
+
1772
+ </body>
1773
+ </html>
1774
+