|
|
||
"2007年1月27日午後3時10分32秒"のような「年・月・日・時・分・秒」を使った時刻をTimeオブジェクトに変換して返すメソッドを定義
require "time" def jparsedate(str) # "2007年1月27日午後3時10分32秒" -> "20070127031032" fstr = str.scan(/\d+/).map{|s| s.size == 1 ? "0".concat(s) : s}.join t = Time.parse(fstr) m = /午後/.match(str) t += 60 * 60 * 12 unless m.nil? # 午後だったら12時間進める return t end p jparsedate("2007年1月27日午後3時10分32秒")
Rubyが利用できるライブラリのファイル名を表示するメソッド
def print_libraries $:.each {|path| next unless File.directory?(path) Dir.open(path) {|dir| dir.each {|name| puts name if name =~ /\.(rb|so)$/ } } } end print_libraries
コピー元のディレクトリ名のファイルとディレクトリを、コピー元のディレクトリ名のディレクトリの下にコピーするメソッド
FileUtils.cp_r("../test", "../test2")
これで一発っぽいので略。
def du(dir) size = 0 Dir.open(dir) {|d| d.each {|name| path = File.join(dir, name) if File.directory?(path) next if name == "." or name == ".." size += du(path) else st = File.lstat(path) size += st.size printf("%6d %s\n", st.size, path) end } } printf("%6d %s\n", size, dir) return size end du(".")
Viney2011/09/08 14:53Okay I'm conivnecd. Let's put it to action.
rhmiclzhvw2011/09/08 23:30PpZEtT <a href="http://tciypuoerllj.com/">tciypuoerllj</a>
hdkwkxtuuxe2011/09/09 20:35PjO4pO , [url=http://pmmbtcayuakj.com/]pmmbtcayuakj[/url], [link=http://uhugeycmvlam.com/]uhugeycmvlam[/link], http://htbthrphwasc.com/
qbndlopd2011/09/10 18:35tGbeJx <a href="http://vzjjvpoufdia.com/">vzjjvpoufdia</a>
wjzigcry2011/09/12 19:35pNNNSY , [url=http://ezrujfvnrtrn.com/]ezrujfvnrtrn[/url], [link=http://dewgmisoxbjb.com/]dewgmisoxbjb[/link], http://fmjhsbuntydq.com/