From: Robert Klemme Date: 2010-03-26T18:15:54+09:00 Subject: Re: Creating a gsub! method for Arrays 2010/3/26 Derek Cannon : > After playing around some more, I've found a solution. > > For anyone who is interested, the following code works: > > class Array >  def gsub!(pattern, replacement) >    each { |x| >      x.gsub!(pattern, replacement) >      } >  end > end What is the benefit of doing arr.gsub! /foo/, 'bar' over arr.each {|s| s.gsub! /foo/, 'bar'} ? Frankly I'd rather use the latter form. Because otherwise you'll have to put a method in Array (or Enumerable for that matter) for *every* operation you want to apply to elements. Additionally, there is another point: since you made Array#gsub! look like String#gsub! this might confuse readers of the code - especially if someone picks bad variable names like "a". Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/