Is there a way to “cast” or “convert” an Array to a Slice? Like a canonical way?
Just wondering for some unit tests I’m working on for the stdlib where I want to do
(1..17).to_a.to_slice
Is there a way to “cast” or “convert” an Array to a Slice? Like a canonical way?
Just wondering for some unit tests I’m working on for the stdlib where I want to do
(1..17).to_a.to_slice
Why do you need this?
So I could new up a Slice[1,2,3,4,5...17]
for unit tests for the Slice class.
I did find a constructor that seems to work :)
def to_slice(arr)
Slice.new(arr.size) {|i| arr[i]}
end