Ruby won't write to file but won't print error -


i'm writing little memo script, , after running , testing it, doesn't output file, , it's making me pull out hair nothing change fixes problem. file gets created, stays empty.

require 'ruby-progressbar' puts "loading..." lt = progressbar.create if file.directory?("./memos") == false     lt.progress = 50     dir.mkdir("memos")     lt.progress = 100 end lt.progress = 100 dir.chdir("memos") puts "welcome eternal memorizer." loop     progress = progressbar.create     progress.log "getting files..."     progress.progress = 50     cdf = dir.glob("**/*")      progress.progress = 100     puts "memos:"     puts cdf     puts ""     puts "[m]ake memo, [r]ead memo, [d]elete memo."     op = gets.chomp     if op.downcase == "m"         print "memo name: "         nam = gets.chomp         puts "\ntext, press enter finish:"         txt = gets.chomp         num = txt.length         txt = txt.split('')         ggg = progressbar.create(:title => "saving...", :total => num)         o = file.open("#{nam}.mem", 'w+')         = 0         ggg.log "writing #{txt.join}"         num.times             puts txt             #sleep(30)             o.write("#{txt[i]}")             += 1             ggg.increment             ggg.title = "#{txt[i]}"             #system("cls"); system("clear")         end     elsif op.downcase == "r"         puts "which memo open?"         fil = gets.chomp         begin             fil = file.open("#{fil}", 'r+')             puts "\n-=-=-=-"             puts fil.read             puts "-=-=-=-\n"         rescue             puts "err, unable open file."         end     elsif op.downcase == "d"         puts "which memo delete?"         file.delete(gets.chomp)     end end 

i've read , reread through it, , it's hit point i've given on it, it'd big if error found.

either close file manually after you're done writing it.

o.close 

this should commit disk.

or use block form of file.open handles closing of file.

file.open("#{nam}.mem", 'w+') |o|   = 0   ggg.log "writing #{txt.join}"   num.times       puts txt       #sleep(30)       o.write("#{txt[i]}")       += 1       ggg.increment       ggg.title = "#{txt[i]}"       #system("cls"); system("clear")   end end 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -