From: gotoken@... (GOTO Kentaro) Date: 2000-12-31T18:27:03+09:00 Subject: [ruby-talk:8386] Re: substitution / Ruby's RegExp's In message "[ruby-talk:8385] substitution / Ruby's RegExp's" on 00/12/31, Jens Luedicke writes: >My problem is that I want to replace every occurance >of a pattern in an array... > >for i in file > i =~ # substitution here >end > >A Perl-Style substitution like: > > s/old/new/g; > >doesn't work and Ruby's Reference/Tutorial >wasn't helpful at all to me. String#gsub! is a way. For example: for line in file line.gsub!(old, new) end where old is a string or a regular expression. In Ruby, every data manipulation is archived by a method, e.g., even the matching operator =~ is a special form of method invocaion, and we denote it by String#=~ (=~ method of String class) or Regexp#=~ (=~ of Regexp). When I would like to know how to do something against an object, so, I check out the reference manual about the class of the object or its operand. Hope this helps, -- Gotoken