Created
April 20, 2012 07:58
-
-
Save klodio/2426996 to your computer and use it in GitHub Desktop.
replace stuff in a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hahahahaha, I should just have used sed