|
[ruby-list:42082] Re: puts,printの出力をファイルにも出力するには: msg#00113lang.ruby.japanese
Gimiteです。 > 単純なトップレベルでのputsの再定義ですが、 > alias old_puts puts > alias old_print print > def set_output_file(file) > $h_output=open(file,"w") > end > > def puts(*arg) > $h_output.old_puts *arg > STDOUT.old_puts *arg > end これとあまり変わりませんが、 $out_file= open("log.txt", "w") def $stdout.write(str) super(str) $out_file.write(str) end とすれば、$stdoutに出力する関数(putsとかprintとかprintfとか)の挙動を いっぺんに変更できるようです。 -- Gimite 市川 <gimite-6zHM6C0iXZ9UD6l512u9tw@xxxxxxxxxxxxxxxx>
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [ruby-list:42081] Re: NKF MIME encode problem, しん |
|---|---|
| Next by Date: | [ruby-list:42083] Re: NKF MIME encode problem, Takahiro Kambe |
| Previous by Thread: | [ruby-list:42075] Re: puts,printの出力をファイルにも出力するには, Hidetoshi NAGAI |
| Next by Thread: | [ruby-list:42065] Re: puts,printの出力をファイルにも出力するには, 岩崎 弘孝 |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |