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.
Map is probably the best way, but you can change the string in-place too.
> a = "hello"
> puts a
=> hello
> a.replace("hi")
> puts a
=> hi
changes the internal value of the string. For example, your code could become :
x = %w(hello there world)
x.each { |e| if (e == "hello"); e.replace("hi") end; }
but this is much nicer :
x = %w(hello there world)
x.map! { |e| e == "hello" ? "hi" : e }