File.open, write and save? File.open, write and save? ruby ruby

File.open, write and save?


If you just need to perform a simple script like creating a file, you can simply use a Ruby script without creating a rake task.

# file origin.rbtarget  = "target.rb"content = <<-RUBY  puts "I'm the target!"RUBYFile.open(target, "w+") do |f|  f.write(content)end

And you can execute the file with

$ ruby origin.rb


directory = "../../directory"File.open(File.join(directory, 'file.rb'), 'w') do |f|  f.puts "contents"end


This turned out to be the best solution.

File.open("linecount.txt",'w') do |filea|  File.open("testfile.txt",'r') do |fileb|    while line = fileb.gets      filea.puts line.length    end  endend