Skip to content

Commit 5a5e135

Browse files
committed
Add a touch of doc around the Array extension.
1 parent fb477b8 commit 5a5e135

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/base58/extensions/array.cr

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
class Array
2+
# This is a convenience method for creating a Slice from an Array. It is the equivalent
3+
# of writing:
4+
#
5+
# ```
6+
# Slice.new(array.size) { |idx| array[idx] }
7+
# ```
8+
#
9+
# Use cases are primarily for convenience and readability.
10+
#
11+
# ```
12+
# # In a spec, you need a Slice of 10 elements.
13+
# [1, 2, 3, 5, 7, 11, 13, 17, 19, 23].to_slice
14+
#
15+
# # In a spec, you have a method that is returning an array, but your original
16+
# # data is in a slice.
17+
# do_something_and_get_an_array.to_slice.should eq original_slice
18+
# ```
19+
#
220
def to_slice
321
Slice.new(self.size) { |idx| self[idx] }
422
end

0 commit comments

Comments
 (0)