Skip to content

Instantly share code, notes, and snippets.

@klodio
Created April 20, 2012 07:58
Show Gist options
  • Save klodio/2426996 to your computer and use it in GitHub Desktop.
Save klodio/2426996 to your computer and use it in GitHub Desktop.
replace stuff in a file
def replace_in_file(options)
needles=options[:search_replace] #a hash like {"replace this"=>"with that"}
File.open(options[:file_path],"r+"){ |handle|
data=handle.read
needles.each { |key, value|
data.gsub!(key,value)
}
handle.rewind
handle.write(data)
}
end
@klodio
Copy link
Author

klodio commented May 30, 2012

hahahahaha, I should just have used sed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment