在 Ruby 中使用 Range 填充数组的正确方法 - Correct way to populate an Array with a Range in Ruby

问题:

I am working through a book which gives examples of Ranges being converted to equivalent arrays using their "to_a" methods我正在阅读一本书,其中给出了使用“to_a”方法将范围转换为等效数组的示例

When i run the code in irb I get the following warning当我在 irb 中运行代码时,我收到以下警告

 warning: default `to_a' will be obsolete

What is the the correct alternative to using to_a?使用 to_a 的正确替代方法是什么?

are there alternate ways to populate an array with a Range?有没有其他方法可以用 Range 填充数组?


解决方案:

参考一: https://en.stackoom.com/question/nlx
参考二: https://stackoom.com/question/nlx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章