You can get the result you want using collect! or map! to modify the array in-place:
x = %w(hello there world)
x.collect! { |element|
(element == "hello") ? "hi" : element
}
puts x
At each iteration, the element is replaced into the array by the value returned by the block.