初めて Ruby でスクリプト書いてみました。
使い方とかは、ソースを読んで想像してみてください。
require 'date' income = 100000 # 今月の収入から、予定出費を引いた金額 def total_cost return 0 unless File.exists?(@filename) total_cost = 0 open @filename do |f| f.each { |line| total_cost += line.to_i } end total_cost end now = Time.now days = Date.new(now.year, now.month, -1).day @filename = File.dirname(__FILE__) + '/' + sprintf('%s%02d.txt', now.year.to_s[2..-1], now.month) loop do puts '使える額: ¥' + (income / days * now.day - total_cost).to_s print '使用額(Ctrl+Dで終了): ¥' cost = gets.to_i if cost > 0 open(@filename, 'a') { |f| f.puts cost } else break end end