I redefined Array#replace like follows.
require 'test/unit'
class Array
def replace (from, to)
each_with_index do |e, i|
self[i] = to if e = from
end
end
end
class TestDriver <Test::Unit::TestCase
def test_replace
book_topic = ['html', 'java', 'css']
book_topic.replace('java', 'ruby')
result_topic = ['html', 'ruby', 'css']
assert_equal book_topic, result_topic
end
end
When I run that test case, it asserts the book_topic is ['html', 'ruby', 'ruby']. I have no idea about the result of book_topic. Can anyone tell me why?