Ruby のメモ
コーディングスタイル
Tips
- 以下のコードを実行するとそれ以降print, putsなどの出力がファイルと標準出力の両方に行われます。
defout = Object.new defout.instance_eval{@ofile=open("/path/to/log/file", "w")} class <<defout def write(str) STDOUT.write(str) @ofile.write(str) end end $stdout = defout- redirectは行っていないのでsystemなど子プロセスの出力はファイルには出力されません。
- http://osdir.com/ml/lang.ruby.japanese/2006-04/msg00107.html
- http://osdir.com/ml/lang.ruby.japanese/2006-04/msg00108.html
Ruby 環境
- require 'rbconfig' で設定を取得 (rbconfig)
- ruby -rrbconfig -e "puts RbConfig::CONFIG['rubylibdir']" で /usr/lib/ruby/1.8 を得るとか
