ruby file code example
Example 1: 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
Example 2: load file in terminal ruby
launch irb
require './ruby_file.rb'