On 3/18/2011 10:22, Ruby Fan wrote:
> Found way:
> 
> b = []
> a[3...7].size.times do b.push("B") end
> a[3...7] = b
> 
> is there anything simplier?

Not necessarily any simpler, but perhaps a bit more efficient:

3...7.each { |i| a[i] = "B" }

Wrap it up into a nice method:

class Array
  def replace_range_with(range, replacement)
    range.each { |i| self[i] = replacement }
    self
  end
end

a = ["A", "A", "A", "A", "A"]
a.replace_range_with(2...4, "B") #=> ["A", "A", "B", "B", "A"]


-Jeremy