shenanigans 1.0.13 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shenanigans/array/caret.rb +3 -2
  3. data/lib/shenanigans/array/random_subarray.rb +7 -5
  4. data/lib/shenanigans/array/reductions.rb +13 -10
  5. data/lib/shenanigans/array/zip_with.rb +9 -12
  6. data/lib/shenanigans/array.rb +3 -3
  7. data/lib/shenanigans/hash/extract.rb +5 -4
  8. data/lib/shenanigans/hash/has_shape_pred.rb +6 -7
  9. data/lib/shenanigans/hash/to_ostruct.rb +8 -9
  10. data/lib/shenanigans/hash.rb +3 -3
  11. data/lib/shenanigans/integer/divisible_by.rb +13 -0
  12. data/lib/shenanigans/integer/string_length.rb +13 -0
  13. data/lib/shenanigans/integer.rb +2 -0
  14. data/lib/shenanigans/kernel/fn.rb +7 -6
  15. data/lib/shenanigans/kernel/prompt.rb +6 -7
  16. data/lib/shenanigans/kernel/require_optional.rb +8 -8
  17. data/lib/shenanigans/kernel/with.rb +4 -3
  18. data/lib/shenanigans/kernel.rb +4 -4
  19. data/lib/shenanigans/module/private_accessor.rb +6 -6
  20. data/lib/shenanigans/module.rb +1 -1
  21. data/lib/shenanigans/object/display.rb +5 -4
  22. data/lib/shenanigans/object.rb +1 -2
  23. data/lib/shenanigans/string/cmpi.rb +4 -3
  24. data/lib/shenanigans/string/in_groups_of.rb +4 -6
  25. data/lib/shenanigans/string.rb +2 -2
  26. data/lib/shenanigans.rb +7 -7
  27. metadata +81 -51
  28. data/Gemfile +0 -8
  29. data/doc/Array.html +0 -519
  30. data/doc/Fixnum.html +0 -215
  31. data/doc/Hash.html +0 -417
  32. data/doc/Kernel.html +0 -460
  33. data/doc/Module.html +0 -237
  34. data/doc/Object.html +0 -286
  35. data/doc/String.html +0 -299
  36. data/doc/_index.html +0 -185
  37. data/doc/class_list.html +0 -51
  38. data/doc/css/common.css +0 -1
  39. data/doc/css/full_list.css +0 -58
  40. data/doc/css/style.css +0 -499
  41. data/doc/file.README.html +0 -160
  42. data/doc/file_list.html +0 -56
  43. data/doc/frames.html +0 -17
  44. data/doc/index.html +0 -160
  45. data/doc/js/app.js +0 -248
  46. data/doc/js/full_list.js +0 -216
  47. data/doc/js/jquery.js +0 -4
  48. data/doc/method_list.html +0 -187
  49. data/doc/top-level-namespace.html +0 -112
  50. data/lib/shenanigans/fixnum/string_length.rb +0 -14
  51. data/lib/shenanigans/fixnum.rb +0 -1
  52. data/lib/shenanigans/object/it.rb +0 -9
  53. data/test/array/test_caret.rb +0 -9
  54. data/test/array/test_random_subarray.rb +0 -10
  55. data/test/array/test_reductions.rb +0 -27
  56. data/test/array/test_zip_with.rb +0 -14
  57. data/test/fixnum/test_string_length.rb +0 -16
  58. data/test/hash/test_extract.rb +0 -11
  59. data/test/hash/test_has_shape_pred.rb +0 -40
  60. data/test/hash/test_to_ostruct.rb +0 -23
  61. data/test/kernel/test_fn.rb +0 -14
  62. data/test/kernel/test_prompt.rb +0 -27
  63. data/test/kernel/test_require_optional.rb +0 -17
  64. data/test/kernel/test_with.rb +0 -12
  65. data/test/module/test_private_accessor.rb +0 -21
  66. data/test/object/test_display.rb +0 -36
  67. data/test/object/test_it.rb +0 -10
  68. data/test/string/test_cmpi.rb +0 -10
  69. data/test/string/test_in_groups_of.rb +0 -11
data/doc/Fixnum.html DELETED
@@ -1,215 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Class: Fixnum
8
-
9
- &mdash; Documentation by YARD 0.9.12
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "Fixnum";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (F)</a> &raquo;
40
-
41
-
42
- <span class="title">Fixnum</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Class: Fixnum
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
- <dl>
70
- <dt>Inherits:</dt>
71
- <dd>
72
- <span class="inheritName"><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></span>
73
-
74
- <ul class="fullTree">
75
- <li><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></li>
76
-
77
- <li class="next">Fixnum</li>
78
-
79
- </ul>
80
- <a href="#" class="inheritanceTree">show all</a>
81
-
82
- </dd>
83
- </dl>
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
- <dl>
96
- <dt>Defined in:</dt>
97
- <dd>lib/shenanigans/fixnum/string_length.rb</dd>
98
- </dl>
99
-
100
- </div>
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
- <h2>
111
- Instance Method Summary
112
- <small><a href="#" class="summary_toggle">collapse</a></small>
113
- </h2>
114
-
115
- <ul class="summary">
116
-
117
- <li class="public ">
118
- <span class="summary_signature">
119
-
120
- <a href="#string_length-instance_method" title="#string_length (instance method)">#<strong>string_length</strong> &#x21d2; Object </a>
121
-
122
-
123
-
124
- </span>
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
- <span class="summary_desc"><div class='inline'>
135
- <p>Returns the length of the number&#39;s string representation.</p>
136
- </div></span>
137
-
138
- </li>
139
-
140
-
141
- </ul>
142
-
143
-
144
-
145
-
146
- <div id="instance_method_details" class="method_details_list">
147
- <h2>Instance Method Details</h2>
148
-
149
-
150
- <div class="method_details first">
151
- <h3 class="signature first" id="string_length-instance_method">
152
-
153
- #<strong>string_length</strong> &#x21d2; <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
154
-
155
-
156
-
157
-
158
-
159
- </h3><div class="docstring">
160
- <div class="discussion">
161
-
162
- <p>Returns the length of the number&#39;s string representation.</p>
163
-
164
- <pre class="code ruby"><code class="ruby"><span class='int'>0</span><span class='period'>.</span><span class='id identifier rubyid_string_length'>string_length</span>
165
- <span class='comment'>#=&gt; 1
166
- </span><span class='int'>123</span><span class='period'>.</span><span class='id identifier rubyid_string_length'>string_length</span>
167
- <span class='comment'>#=&gt; 3
168
- </span><span class='op'>-</span><span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_string_length'>string_length</span>
169
- <span class='comment'>#=&gt; 2
170
- </span></code></pre>
171
-
172
-
173
- </div>
174
- </div>
175
- <div class="tags">
176
-
177
-
178
- </div><table class="source_code">
179
- <tr>
180
- <td>
181
- <pre class="lines">
182
-
183
-
184
- 9
185
- 10
186
- 11
187
- 12
188
- 13</pre>
189
- </td>
190
- <td>
191
- <pre class="code"><span class="info file"># File 'lib/shenanigans/fixnum/string_length.rb', line 9</span>
192
-
193
- <span class='kw'>def</span> <span class='id identifier rubyid_string_length'>string_length</span>
194
- <span class='kw'>return</span> <span class='int'>1</span> <span class='kw'>if</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
195
- <span class='id identifier rubyid_len'>len</span> <span class='op'>=</span> <span class='const'>Math</span><span class='period'>.</span><span class='id identifier rubyid_log10'>log10</span><span class='lparen'>(</span><span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_abs'>abs</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_floor'>floor</span><span class='period'>.</span><span class='id identifier rubyid_next'>next</span>
196
- <span class='kw'>self</span> <span class='op'>&gt;</span> <span class='int'>0</span> <span class='op'>?</span> <span class='id identifier rubyid_len'>len</span> <span class='op'>:</span> <span class='id identifier rubyid_len'>len</span><span class='period'>.</span><span class='id identifier rubyid_next'>next</span>
197
- <span class='kw'>end</span></pre>
198
- </td>
199
- </tr>
200
- </table>
201
- </div>
202
-
203
- </div>
204
-
205
- </div>
206
-
207
- <div id="footer">
208
- Generated on Thu Feb 1 16:36:55 2018 by
209
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
210
- 0.9.12 (ruby-2.5.0).
211
- </div>
212
-
213
- </div>
214
- </body>
215
- </html>
data/doc/Hash.html DELETED
@@ -1,417 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Class: Hash
8
-
9
- &mdash; Documentation by YARD 0.9.12
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "Hash";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (H)</a> &raquo;
40
-
41
-
42
- <span class="title">Hash</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Class: Hash
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
- <dl>
70
- <dt>Inherits:</dt>
71
- <dd>
72
- <span class="inheritName"><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></span>
73
-
74
- <ul class="fullTree">
75
- <li><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></li>
76
-
77
- <li class="next">Hash</li>
78
-
79
- </ul>
80
- <a href="#" class="inheritanceTree">show all</a>
81
-
82
- </dd>
83
- </dl>
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
- <dl>
96
- <dt>Defined in:</dt>
97
- <dd>lib/shenanigans/hash/extract.rb<span class="defines">,<br />
98
- lib/shenanigans/hash/to_ostruct.rb,<br /> lib/shenanigans/hash/has_shape_pred.rb</span>
99
- </dd>
100
- </dl>
101
-
102
- </div>
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
- <h2>
113
- Instance Method Summary
114
- <small><a href="#" class="summary_toggle">collapse</a></small>
115
- </h2>
116
-
117
- <ul class="summary">
118
-
119
- <li class="public ">
120
- <span class="summary_signature">
121
-
122
- <a href="#extract-instance_method" title="#extract (instance method)">#<strong>extract</strong>(*ks) &#x21d2; Object </a>
123
-
124
-
125
-
126
- </span>
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
- <span class="summary_desc"><div class='inline'>
137
- <p>Returns a new hash only with the specified keys (if present).</p>
138
- </div></span>
139
-
140
- </li>
141
-
142
-
143
- <li class="public ">
144
- <span class="summary_signature">
145
-
146
- <a href="#has_shape%3F-instance_method" title="#has_shape? (instance method)">#<strong>has_shape?</strong>(shape) &#x21d2; Boolean </a>
147
-
148
-
149
-
150
- </span>
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
- <span class="summary_desc"><div class='inline'>
161
- <p>Checks if a hash has a certain structure.</p>
162
- </div></span>
163
-
164
- </li>
165
-
166
-
167
- <li class="public ">
168
- <span class="summary_signature">
169
-
170
- <a href="#to_ostruct-instance_method" title="#to_ostruct (instance method)">#<strong>to_ostruct</strong> &#x21d2; Object </a>
171
-
172
-
173
-
174
- </span>
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
- <span class="summary_desc"><div class='inline'>
185
- <p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es
186
- to <code>OpenStruct</code>s.</p>
187
- </div></span>
188
-
189
- </li>
190
-
191
-
192
- </ul>
193
-
194
-
195
-
196
-
197
- <div id="instance_method_details" class="method_details_list">
198
- <h2>Instance Method Details</h2>
199
-
200
-
201
- <div class="method_details first">
202
- <h3 class="signature first" id="extract-instance_method">
203
-
204
- #<strong>extract</strong>(*ks) &#x21d2; <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
205
-
206
-
207
-
208
-
209
-
210
- </h3><div class="docstring">
211
- <div class="discussion">
212
-
213
- <p>Returns a new hash only with the specified keys (if present).</p>
214
-
215
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_hash'>hash</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>a:</span> <span class='int'>1</span><span class='comma'>,</span> <span class='label'>b:</span> <span class='int'>2</span><span class='comma'>,</span> <span class='label'>c:</span> <span class='int'>3</span> <span class='rbrace'>}</span>
216
- <span class='id identifier rubyid_hash'>hash</span><span class='period'>.</span><span class='id identifier rubyid_extract'>extract</span><span class='lparen'>(</span><span class='symbol'>:b</span><span class='comma'>,</span> <span class='symbol'>:a</span><span class='rparen'>)</span>
217
- <span class='comment'>#=&gt; { a: 1, b: 2 }
218
- </span><span class='id identifier rubyid_hash'>hash</span><span class='period'>.</span><span class='id identifier rubyid_extract'>extract</span><span class='lparen'>(</span><span class='symbol'>:a</span><span class='comma'>,</span> <span class='symbol'>:d</span><span class='rparen'>)</span>
219
- <span class='comment'>#=&gt; { a: 1}
220
- </span></code></pre>
221
-
222
-
223
- </div>
224
- </div>
225
- <div class="tags">
226
-
227
-
228
- </div><table class="source_code">
229
- <tr>
230
- <td>
231
- <pre class="lines">
232
-
233
-
234
- 8
235
- 9
236
- 10
237
- 11</pre>
238
- </td>
239
- <td>
240
- <pre class="code"><span class="info file"># File 'lib/shenanigans/hash/extract.rb', line 8</span>
241
-
242
- <span class='kw'>def</span> <span class='id identifier rubyid_extract'>extract</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_ks'>ks</span><span class='rparen'>)</span>
243
- <span class='id identifier rubyid_existing'>existing</span> <span class='op'>=</span> <span class='id identifier rubyid_keys'>keys</span> <span class='op'>&amp;</span> <span class='id identifier rubyid_ks'>ks</span>
244
- <span class='const'><span class='object_link'><a href="" title="Hash (class)">Hash</a></span></span><span class='lbracket'>[</span><span class='id identifier rubyid_existing'>existing</span><span class='period'>.</span><span class='id identifier rubyid_zip'>zip</span><span class='lparen'>(</span><span class='id identifier rubyid_values_at'>values_at</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_existing'>existing</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rbracket'>]</span>
245
- <span class='kw'>end</span></pre>
246
- </td>
247
- </tr>
248
- </table>
249
- </div>
250
-
251
- <div class="method_details ">
252
- <h3 class="signature " id="has_shape?-instance_method">
253
-
254
- #<strong>has_shape?</strong>(shape) &#x21d2; <tt>Boolean</tt>
255
-
256
-
257
-
258
-
259
-
260
- </h3><div class="docstring">
261
- <div class="discussion">
262
-
263
- <p>Checks if a hash has a certain structure.</p>
264
-
265
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_h'>h</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>k1:</span> <span class='int'>1</span><span class='comma'>,</span> <span class='label'>k2:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>1</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
266
- <span class='id identifier rubyid_h'>h</span><span class='period'>.</span><span class='id identifier rubyid_has_shape?'>has_shape?</span><span class='lparen'>(</span><span class='label'>k1:</span> <span class='const'><span class='object_link'><a href="Fixnum.html" title="Fixnum (class)">Fixnum</a></span></span><span class='comma'>,</span> <span class='label'>k2:</span> <span class='const'><span class='object_link'><a href="String.html" title="String (class)">String</a></span></span><span class='rparen'>)</span>
267
- <span class='comment'>#=&gt; true
268
- </span><span class='id identifier rubyid_h'>h</span><span class='period'>.</span><span class='id identifier rubyid_has_shape?'>has_shape?</span><span class='lparen'>(</span><span class='label'>k1:</span> <span class='const'>Class</span><span class='comma'>,</span> <span class='label'>k2:</span> <span class='const'><span class='object_link'><a href="String.html" title="String (class)">String</a></span></span><span class='rparen'>)</span>
269
- <span class='comment'>#=&gt; false
270
- </span></code></pre>
271
-
272
- <p>It also works with compound data structures.</p>
273
-
274
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_h'>h</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>k1:</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='label'>k2:</span> <span class='lbrace'>{</span> <span class='label'>k3:</span> <span class='const'>Struct</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Foo</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='rbrace'>}</span>
275
- <span class='id identifier rubyid_shape'>shape</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>k1:</span> <span class='const'><span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span></span><span class='comma'>,</span> <span class='label'>k2:</span> <span class='lbrace'>{</span> <span class='label'>k3:</span> <span class='const'><span class='object_link'><a href="Module.html" title="Module (class)">Module</a></span></span> <span class='rbrace'>}</span> <span class='rbrace'>}</span>
276
- <span class='id identifier rubyid_h'>h</span><span class='period'>.</span><span class='id identifier rubyid_has_shape?'>has_shape?</span><span class='lparen'>(</span><span class='id identifier rubyid_shape'>shape</span><span class='rparen'>)</span>
277
- <span class='comment'>#=&gt; true
278
- </span></code></pre>
279
-
280
-
281
- </div>
282
- </div>
283
- <div class="tags">
284
-
285
- <p class="tag_title">Returns:</p>
286
- <ul class="return">
287
-
288
- <li>
289
-
290
-
291
- <span class='type'>(<tt>Boolean</tt>)</span>
292
-
293
-
294
-
295
- </li>
296
-
297
- </ul>
298
-
299
- </div><table class="source_code">
300
- <tr>
301
- <td>
302
- <pre class="lines">
303
-
304
-
305
- 13
306
- 14
307
- 15
308
- 16
309
- 17</pre>
310
- </td>
311
- <td>
312
- <pre class="code"><span class="info file"># File 'lib/shenanigans/hash/has_shape_pred.rb', line 13</span>
313
-
314
- <span class='kw'>def</span> <span class='id identifier rubyid_has_shape?'>has_shape?</span><span class='lparen'>(</span><span class='id identifier rubyid_shape'>shape</span><span class='rparen'>)</span>
315
- <span class='id identifier rubyid_all?'>all?</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span>
316
- <span class='const'><span class='object_link'><a href="" title="Hash (class)">Hash</a></span></span> <span class='op'>===</span> <span class='id identifier rubyid_v'>v</span> <span class='op'>?</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_has_shape?'>has_shape?</span><span class='lparen'>(</span><span class='id identifier rubyid_shape'>shape</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='op'>:</span> <span class='id identifier rubyid_shape'>shape</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>===</span> <span class='id identifier rubyid_v'>v</span>
317
- <span class='kw'>end</span>
318
- <span class='kw'>end</span></pre>
319
- </td>
320
- </tr>
321
- </table>
322
- </div>
323
-
324
- <div class="method_details ">
325
- <h3 class="signature " id="to_ostruct-instance_method">
326
-
327
- #<strong>to_ostruct</strong> &#x21d2; <tt><span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span></tt>
328
-
329
-
330
-
331
-
332
-
333
- </h3><div class="docstring">
334
- <div class="discussion">
335
-
336
- <p>Recursively converts a <code>Hash</code> and all nested <code>Hash</code>es
337
- to <code>OpenStruct</code>s. Especially useful for parsing YAML.</p>
338
-
339
- <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_yaml'>yaml</span><span class='op'>=</span><span class='heredoc_beg'>&lt;&lt;EOY</span>
340
- <span class='tstring_content'>subject: Programming Languages
341
- languages:
342
- - name : Ruby
343
- creator : Matz
344
- - name : Python
345
- creator : Guido van Rossum
346
- - name : Perl
347
- creator : Larry Wall
348
- </span><span class='heredoc_end'>EOY
349
- </span><span class='id identifier rubyid_struct'>struct</span> <span class='op'>=</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_yaml'>yaml</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_ostruct'>to_ostruct</span>
350
- <span class='id identifier rubyid_struct'>struct</span><span class='period'>.</span><span class='id identifier rubyid_subject'>subject</span>
351
- <span class='comment'>#=&gt; &quot;Programming Languages&quot;
352
- </span><span class='id identifier rubyid_struct'>struct</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span>
353
- <span class='comment'>#=&gt; #&lt;OpenStruct name=&quot;Ruby&quot;, creator=&quot;Matz&quot;&gt;
354
- </span><span class='id identifier rubyid_struct'>struct</span><span class='period'>.</span><span class='id identifier rubyid_languages'>languages</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='period'>.</span><span class='id identifier rubyid_creator'>creator</span>
355
- <span class='comment'>#=&gt; &quot;Matz&quot;
356
- </span></code></pre>
357
-
358
-
359
- </div>
360
- </div>
361
- <div class="tags">
362
-
363
-
364
- </div><table class="source_code">
365
- <tr>
366
- <td>
367
- <pre class="lines">
368
-
369
-
370
- 23
371
- 24
372
- 25
373
- 26
374
- 27
375
- 28
376
- 29
377
- 30
378
- 31
379
- 32
380
- 33
381
- 34
382
- 35</pre>
383
- </td>
384
- <td>
385
- <pre class="code"><span class="info file"># File 'lib/shenanigans/hash/to_ostruct.rb', line 23</span>
386
-
387
- <span class='kw'>def</span> <span class='id identifier rubyid_to_ostruct'>to_ostruct</span>
388
- <span class='id identifier rubyid_arr'>arr</span> <span class='op'>=</span> <span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span>
389
- <span class='kw'>case</span> <span class='id identifier rubyid_v'>v</span>
390
- <span class='kw'>when</span> <span class='const'><span class='object_link'><a href="" title="Hash (class)">Hash</a></span></span>
391
- <span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_to_ostruct'>to_ostruct</span><span class='rbracket'>]</span>
392
- <span class='kw'>when</span> <span class='const'><span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span></span>
393
- <span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_el'>el</span><span class='op'>|</span> <span class='id identifier rubyid_el'>el</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:to_ostruct</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_el'>el</span><span class='period'>.</span><span class='id identifier rubyid_to_ostruct'>to_ostruct</span> <span class='op'>:</span> <span class='id identifier rubyid_el'>el</span> <span class='rbrace'>}</span><span class='rbracket'>]</span>
394
- <span class='kw'>else</span>
395
- <span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='rbracket'>]</span>
396
- <span class='kw'>end</span>
397
- <span class='kw'>end</span>
398
- <span class='const'>OpenStruct</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="" title="Hash (class)">Hash</a></span></span><span class='lbracket'>[</span><span class='id identifier rubyid_arr'>arr</span><span class='rbracket'>]</span><span class='rparen'>)</span>
399
- <span class='kw'>end</span></pre>
400
- </td>
401
- </tr>
402
- </table>
403
- </div>
404
-
405
- </div>
406
-
407
- </div>
408
-
409
- <div id="footer">
410
- Generated on Thu Feb 1 16:36:55 2018 by
411
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
412
- 0.9.12 (ruby-2.5.0).
413
- </div>
414
-
415
- </div>
416
- </body>
417
- </html>