Answers for "ruby script to create file"

5

A Ruby write to file example

# open and write to a file with ruby
open('myfile.out', 'w') do |f|
  f.puts "Hello, world."
end

# an alternative approach:
open('myfile.out', 'w') do |f|
  f << "Hello, world.\n"
end
Posted by: Guest on June-18-2020
4

ruby read file

file = File.open("yourPath.txt")
results = file.read
Posted by: Guest on June-17-2020

Browse Popular Code Answers by Language