How do I get the following to happen: I want to change the value of an array element which is being referenced between pipe characters in a .each
loop.
Here is an example of what I want to do, but is not currently working:
x = %w(hello there world)
x.each { |element|
if(element == "hello") {
element = "hi" # change "hello" to "hi"
}
}
puts x # output: [hi there world]
It's hard to look up something so general.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…