Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在这个网站上看到了 Ruby 中的一个单行代码,但忘记了:
如果我需要用整数打印某些操作的结果:
print {|e| e = e * e}
但是我如何让 Ruby 知道 e 是 1 到 10?
在您的范围内使用括号
(1..10).map {|ele| ele + 3} // 1 to 10 including the last number (1...10).map {|ele| ele + 3 } // 1 to 9 excluding the last number
目前还不清楚你想做什么,但这里有一个输入
(1..10).to_a
这为您提供了一个从 1 到 10 的数字数组。