rubyサンプルプログラム採集家です
rubyとruby on rails書籍のサンプルプログラム配布サイトの一覧
こういうのでサンプルプログラムがディレクトリまたいでるのファイルを結合するプログラムです
拡張子も選択できます
手元もruby1.8だと文字化けするけどほかの環境は試してないです
all.rb
# coding: utf-8
def glob_by_extension(extension)
Dir.glob("**/*."+extension)
end
def txtadd(file)
File.read(file)
end
def makealltxt(files)
@alltxt = ""
files.each do |file|
@alltxt << txtadd(file)
end
return @alltxt
end
def filewrite(name, txt)
File.write name, txt
end
def file_write_detail(name, txt)
file = File.open(name,"w")
file.puts txt
file.close
end
def deletemyself(files, selffilename=__FILE__)
files.delete(selffilename)
return files
end
files = glob_by_extension("rb")
txt = ""
txt = makealltxt(deletemyself(files))
#txt.encode#("UTF-8", "Shift_JIS")
p filewrite("combining.rb", txt)