Skip to content

Instantly share code, notes, and snippets.

@xcobar
Last active December 25, 2018 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcobar/400989355ae2e5b0068d0b0561c9f6c6 to your computer and use it in GitHub Desktop.
Save xcobar/400989355ae2e5b0068d0b0561c9f6c6 to your computer and use it in GitHub Desktop.
lines = File.readlines('file.rb')
File.open('file.rb', 'r+') do |f|
f.each_line do |line|
if line.start_with?('dog', 'cat')
line.gsub!(/food/, '')
end
end
end
# example this should become
# cat's are really nice sometimes, we give them good cat food.
# dog's are nice too
# should become
# cat's are really nice sometimes, we give them good cat .
# dog's are nice too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment