From: Art Gillespie Date: 2005-12-31T17:30:24+09:00 Subject: Newb: Search & Replace Hi all, I'm implementing build automation in Ruby as a 'learn Ruby' exercise. I wanted to post the following code and solicit feedback on any idioms I might have missed with regards to text processing with Ruby. The code works--I'm just wondering if it should be shorter, or smarter, or... Thanks, Art --- #!/usr/bin/env ruby VERSION_HEX=ARGV[0] File.open("iDrum_prefix.h.tmp", "w") do |ofile| File.open("iDrum_prefix.h") do |file| file.each do |line| if line =~ /^#define kIDComponentVersion\t*(.*)/ ofile.puts line.sub($1, "#{VERSION_HEX}") else ofile.puts line end end end end File.rename("iDrum_prefix.h.tmp", "iDrum_prefix.h")