如何得到以下情况:我想更改.each
循环中管道字符之间引用的数组元素的值。更改.each循环中引用的数组元素的值?
这里是我想要做一个例子,但当前未工作:
x = %w(hello there world)
x.each { |element|
if(element == "hello") {
element = "hi" # change "hello" to "hi"
}
}
puts x # output: [hi there world]
很难查找东西,所以一般。
有一系列名为[Enumerating enumerable]的博客文章(http://www.globalnerdy.com/tag/enumerating-enumerable/),您可能会觉得有用。 – 2011-04-13 22:30:05