I've been studying arrays in Ruby. Specifically the effects of manipulating arrays with a[start, count]
and a[lower_range..upper_range]
in the Ruby Programming 1.9 book.
Specifically, if I have:
a = [1, 3, 5, 7, 9]
and I do the following:
a[2, 2] = 'cat'
I get the output for a: a => [1, 3, "cat", 9]
Instead of what I expected to be [1, 3, "cat", "cat", 9]
Edit: Thank you everyone for your input. All of the methods suggested work. I understand now.
I prefer the Array.new method that was suggested, because with an arbitrary range, like a[2, n], I can simply use, a[2, n] = Array.new(n, "cat")
Fantastic, thanks everyone.