syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
In Ruby how do I write to a file?

Let the syntax do the writing:
mystring = 'hello world'
fh = File.open('/tmp/hello.txt','w')
fh.puts mystring
fh.close
p 'Do it another way'
File.open('/tmp/bye.txt', 'w') { |fh2| fh2.puts 'bye now' }

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me