@@ -100,8 +100,8 @@ <h1 class="class_name">Array</h1>
100
100
< h2 > Description</ h2 >
101
101
< hr />
102
102
< div > < p > ArrayObject represents instance from Array class.
103
- An array is a collection of different objects that are ordered and indexed.
104
- Elements in an array can belong to any class.</ p >
103
+ An array is a collection of different objects that are ordered and indexed.
104
+ Elements in an array can belong to any class.</ p >
105
105
</ div >
106
106
107
107
< h2 > Instance Methods</ h2 >
@@ -112,13 +112,12 @@ <h4 class="method">
112
112
< span class ="title "> []</ span >
113
113
</ h4 >
114
114
< div class ="method-comment "> < p > Retrieves an object in an array using Integer index.
115
- The index starts from 0. It returns < code > null</ code > if the given index is bigger than its size.
116
- //</ p >
115
+ The index starts from 0. It returns < code > null</ code > if the given index is bigger than its size.</ p >
117
116
118
- < pre > < code class ="language-ruby "> a = [1, 2, 3, "a", "b", "c"]
119
- a[0] # => 1
120
- a[3] # => "a"
121
- a[10] # => null
117
+ < pre > < code class ="language-ruby "> a = [1, 2, 3, "a", "b", "c"]
118
+ a[0] # => 1
119
+ a[3] # => "a"
120
+ a[10] # => null
122
121
</ code > </ pre >
123
122
</ div >
124
123
< p class ="source ">
@@ -132,14 +131,13 @@ <h4 class="method">
132
131
< span class ="title "> []=</ span >
133
132
</ h4 >
134
133
< div class ="method-comment "> < p > Assigns value to an array. It requires an index and a value as argument.
135
- The array will expand if the assigned index is bigger than its size.
136
- Returns the assigned value.
137
- //</ p >
134
+ The array will expand if the assigned index is bigger than its size.
135
+ Returns the assigned value.</ p >
138
136
139
- < pre > < code class ="language-ruby "> a = []
140
- a[0] = 10 # => 10
141
- a[3] = 20 # => 20
142
- a # => [10, null, null, 20]
137
+ < pre > < code class ="language-ruby "> a = []
138
+ a[0] = 10 # => 10
139
+ a[3] = 20 # => 20
140
+ a # => [10, null, null, 20]
143
141
</ code > </ pre >
144
142
</ div >
145
143
< p class ="source ">
@@ -152,10 +150,9 @@ <h4 class="method">
152
150
< span class ="prefix "> #</ span >
153
151
< span class ="title "> length</ span >
154
152
</ h4 >
155
- < div class ="method-comment "> < p > Returns the length of the array.
156
- //</ p >
153
+ < div class ="method-comment "> < p > Returns the length of the array.</ p >
157
154
158
- < pre > < code class ="language-ruby "> [1, 2, 3].length # => 3
155
+ < pre > < code class ="language-ruby "> [1, 2, 3].length # => 3
159
156
</ code > </ pre >
160
157
</ div >
161
158
< p class ="source ">
@@ -168,12 +165,11 @@ <h4 class="method">
168
165
< span class ="prefix "> #</ span >
169
166
< span class ="title "> pop</ span >
170
167
</ h4 >
171
- < div class ="method-comment "> < p > Removes the last element in the array and returns it.
172
- //</ p >
168
+ < div class ="method-comment "> < p > Removes the last element in the array and returns it.</ p >
173
169
174
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
175
- a.pop # => 3
176
- a # => [1, 2]
170
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
171
+ a.pop # => 3
172
+ a # => [1, 2]
177
173
</ code > </ pre >
178
174
</ div >
179
175
< p class ="source ">
@@ -186,11 +182,10 @@ <h4 class="method">
186
182
< span class ="prefix "> #</ span >
187
183
< span class ="title "> push</ span >
188
184
</ h4 >
189
- < div class ="method-comment "> < p > Appends the given object to the array and returns the array.
190
- //</ p >
185
+ < div class ="method-comment "> < p > Appends the given object to the array and returns the array.</ p >
191
186
192
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
193
- a.push(4) # => [1, 2, 3, 4]
187
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
188
+ a.push(4) # => [1, 2, 3, 4]
194
189
</ code > </ pre >
195
190
</ div >
196
191
< p class ="source ">
@@ -203,12 +198,11 @@ <h4 class="method">
203
198
< span class ="prefix "> #</ span >
204
199
< span class ="title "> shift</ span >
205
200
</ h4 >
206
- < div class ="method-comment "> < p > Removes the first element in the array and returns it.
207
- //</ p >
201
+ < div class ="method-comment "> < p > Removes the first element in the array and returns it.</ p >
208
202
209
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
210
- a.shift # => 1
211
- a # => [2, 3]
203
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
204
+ a.shift # => 1
205
+ a # => [2, 3]
212
206
</ code > </ pre >
213
207
</ div >
214
208
< p class ="source ">
@@ -221,17 +215,16 @@ <h4 class="method">
221
215
< span class ="prefix "> #</ span >
222
216
< span class ="title "> each</ span >
223
217
</ h4 >
224
- < div class ="method-comment "> < p > Loop through each element with the given block.
225
- //</ p >
218
+ < div class ="method-comment "> < p > Loop through each element with the given block.</ p >
219
+
220
+ < pre > < code class ="language-ruby "> a = ["a", "b", "c"]
226
221
227
- < pre > < code class ="language-ruby "> a = ["a", "b", "c"]
228
- //
229
- a.each do |e|
230
- puts(e + e)
231
- end
232
- # => "aa"
233
- # => "bb"
234
- # => "cc"
222
+ a.each do |e|
223
+ puts(e + e)
224
+ end
225
+ # => "aa"
226
+ # => "bb"
227
+ # => "cc"
235
228
</ code > </ pre >
236
229
</ div >
237
230
< p class ="source ">
@@ -255,15 +248,14 @@ <h4 class="method">
255
248
< span class ="prefix "> #</ span >
256
249
< span class ="title "> map</ span >
257
250
</ h4 >
258
- < div class ="method-comment "> < p > Loop through each element with the given block. Return a new array with each yield element.
259
- //</ p >
251
+ < div class ="method-comment "> < p > Loop through each element with the given block. Return a new array with each yield element.</ p >
252
+
253
+ < pre > < code class ="language-ruby "> a = ["a", "b", "c"]
260
254
261
- < pre > < code class ="language-ruby "> a = ["a", "b", "c"]
262
- //
263
- a.map do |e|
264
- e + e
265
- end
266
- # => ["aa", "bb", "cc"]
255
+ a.map do |e|
256
+ e + e
257
+ end
258
+ # => ["aa", "bb", "cc"]
267
259
</ code > </ pre >
268
260
</ div >
269
261
< p class ="source ">
@@ -277,15 +269,14 @@ <h4 class="method">
277
269
< span class ="title "> select</ span >
278
270
</ h4 >
279
271
< div class ="method-comment "> < p > Loop through each element with the given block.
280
- Return a new array with each element that returns true from yield.
281
- //</ p >
272
+ Return a new array with each element that returns true from yield.</ p >
282
273
283
- < pre > < code class ="language-ruby "> a = [1, 2, 3, 4, 5]
284
- //
285
- a.select do |e|
286
- e + 1 > 3
287
- end
288
- # => [3, 4, 5]
274
+ < pre > < code class ="language-ruby "> a = [1, 2, 3, 4, 5]
275
+
276
+ a.select do |e|
277
+ e + 1 > 3
278
+ end
279
+ # => [3, 4, 5]
289
280
</ code > </ pre >
290
281
</ div >
291
282
< p class ="source ">
@@ -299,12 +290,11 @@ <h4 class="method">
299
290
< span class ="title "> at</ span >
300
291
</ h4 >
301
292
< div class ="method-comment "> < p > Retrieves an object in an array using the index argument.
302
- It raises an error if index out of range.
303
- //</ p >
293
+ It raises an error if index out of range.</ p >
304
294
305
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
306
- a.at(0) # => 1
307
- a.at(10) # => Error
295
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
296
+ a.at(0) # => 1
297
+ a.at(10) # => Error
308
298
</ code > </ pre >
309
299
</ div >
310
300
< p class ="source ">
@@ -317,12 +307,11 @@ <h4 class="method">
317
307
< span class ="prefix "> #</ span >
318
308
< span class ="title "> clear</ span >
319
309
</ h4 >
320
- < div class ="method-comment "> < p > Removes all elements in the array and returns an empty array.
321
- //</ p >
310
+ < div class ="method-comment "> < p > Removes all elements in the array and returns an empty array.</ p >
322
311
323
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
324
- a.clear # => []
325
- a # => []
312
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
313
+ a.clear # => []
314
+ a # => []
326
315
</ code > </ pre >
327
316
</ div >
328
317
< p class ="source ">
@@ -335,12 +324,11 @@ <h4 class="method">
335
324
< span class ="prefix "> #</ span >
336
325
< span class ="title "> concat</ span >
337
326
</ h4 >
338
- < div class ="method-comment "> < p > Appends any number of argument to the array.
339
- //</ p >
327
+ < div class ="method-comment "> < p > Appends any number of argument to the array.</ p >
340
328
341
- < pre > < code class ="language-ruby "> a = [1, 2, 3]
342
- a.concat(4, 5, 6)
343
- a # => [1, 2, 3, 4, 5, 6]
329
+ < pre > < code class ="language-ruby "> a = [1, 2, 3]
330
+ a.concat(4, 5, 6)
331
+ a # => [1, 2, 3, 4, 5, 6]
344
332
</ code > </ pre >
345
333
</ div >
346
334
< p class ="source ">
@@ -354,15 +342,14 @@ <h4 class="method">
354
342
< span class ="title "> count</ span >
355
343
</ h4 >
356
344
< div class ="method-comment "> < p > Loop through each element with the given block.
357
- Return the sum of elements that return true from yield.
358
- //</ p >
345
+ Return the sum of elements that return true from yield.</ p >
346
+
347
+ < pre > < code class ="language-ruby "> a = [1, 2, 3, 4, 5]
359
348
360
- < pre > < code class ="language-ruby "> a = [1, 2, 3, 4, 5]
361
- //
362
- a.count do |e|
363
- e * 2 > 3
364
- end
365
- # => 4
349
+ a.count do |e|
350
+ e * 2 > 3
351
+ end
352
+ # => 4
366
353
</ code > </ pre >
367
354
</ div >
368
355
< p class ="source ">
@@ -376,14 +363,13 @@ <h4 class="method">
376
363
< span class ="title "> rotate</ span >
377
364
</ h4 >
378
365
< div class ="method-comment "> < p > Returns a new array by putting the desired element as the first element.
379
- Use integer index as an argument to retrieve the element.
380
- //</ p >
366
+ Use integer index as an argument to retrieve the element.</ p >
367
+
368
+ < pre > < code class ="language-ruby "> a = ["a", "b", "c", "d"]
381
369
382
- < pre > < code class ="language-ruby "> a = ["a", "b", "c", "d"]
383
- //
384
- a.rotate # => ["b", "c", "d", "a"]
385
- a.rotate(2) # => ["c", "d", "a", "b"]
386
- a.rotate(3) # => ["d", "a", "b", "c"]
370
+ a.rotate # => ["b", "c", "d", "a"]
371
+ a.rotate(2) # => ["c", "d", "a", "b"]
372
+ a.rotate(3) # => ["d", "a", "b", "c"]
387
373
</ code > </ pre >
388
374
</ div >
389
375
< p class ="source ">
0 commit comments