在 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章