I am using Ruby2.7 and trying to slice a an Array
with the method Array.slice
which I thought sliced an Array
with given arguments of indices.
what I have tried:
nums = Array((0..100)).slice(4, 9)
puts nums
the output is:
[4, 5, 6, 7, 8, 9, 10, 11, 12]
I expected it to output:
[4, 5, 6, 7, 8]
Why does Array.slice
work this way and how do I actually slice an Array
with indices?
I can do it easily in python like:
list[index1:index2]
question from:
https://stackoverflow.com/questions/65649430/why-does-the-the-array-slice-method-work-this-way 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…