Trying to do like Replace content in a file between two markers but the accepted answer doesn't seem to be working:
index.html
<!--start-->Hello world<!--end-->
myscript.rb
def replace(file_path, contents)
file = File.open(file_path, "r+")
html = ""
while(!file.eof?)
html += file.readline
end
file.close()
return html.gsub(/<!--start-->(.*)<!--end-->/im, contents)
end
thing = ["Foo", "Bar", "Baz"].sample
replace("/path/to/index.html", thing)
After running ruby myscript.rb
, index.html
remains the same. I'm on Ruby 2.2.0.