Bug #93 [ruby-reference-manual:870]

Tempfile.new にブロックを与えたときの動作

Added by Ken DATE 649 days ago. Updated 405 days ago.

Status :Closed Start :05/19/2008
Priority :Low Due date :
Assigned to :taifu kouya % Done :

100%

Category :doc
Target version :-
reporter :

rock

ruby_version :

1.8,1.9


Description

Tempfile.new の説明に,ブロックを与えたときの動作が書いてありません。

History

06/04/2008 01:29 AM - Yuki Sonoda

  • Priority changed from Normal to Low

06/04/2008 10:25 PM - taifu kouya

  • Status changed from Open to Assigned
  • Assigned to set to taifu kouya
  • % Done changed from 0 to 50
ブロックを与えたときの動作を追加しました。

06/22/2008 02:42 PM - taifu kouya

  • Status changed from Assigned to Closed
  • % Done changed from 50 to 100
done.

Author: kouya
Date: 2008-06-04 22:23:01 +0900
New Revision: 2707

Changed:
 U   doctree/trunk/refm/api/src/tempfile.rd
Log:
edit tempfile.rd Bug #93 [ruby-reference-manual:870]


Modified: doctree/trunk/refm/api/src/tempfile.rd
===================================================================
--- doctree/trunk/refm/api/src/tempfile.rd      2008-06-02 13:47:47 UTC (rev 2706)
+++ doctree/trunk/refm/api/src/tempfile.rd      2008-06-04 13:23:01 UTC (rev 2707)
@@ -17,8 +17,9 @@

 == Class Methods

---- new(basename, tempdir = Dir::tmpdir)
---- open(basename, tempdir = Dir::tmpdir)
+--- new(basename, tempdir = Dir::tmpdir) -> Tempfile
+--- open(basename, tempdir = Dir::tmpdir) -> Tempfile
+--- open(basename, tempdir = Dir::tmpdir){|fp| ...} -> nil

 #@since 1.8.7
 テンポラリファイルを作成し、それを表す Tempfile オブジェクトを生成して返します。
@@ -28,7 +29,9 @@
 "basename.pid.n" というファイル名で
 テンポラリファイルを作成し、インスタンスを返します。
 #@end
+ ブロックを指定して呼び出した場合は、Tempfile オブジェクトを引数として ブロックを実行します。ブロックの実行が終了すると、ファイルは自動的に クローズされ、nilをかえします。

+
 @param basename ファイル名のプレフィクスを文字列で指定します。
 #@since 1.8.7
                文字列の配列を指定した場合、先頭の要素がファイル名のプレフィックス、次の要素が
@@ -48,9 +51,21 @@
   p t2.path                           #=> "/tmp/t20080518-6961-xy2wvx-0.xml"
 #@end

+例2:ブロックを与えた場合
+  require 'tempfile'
+
+  path = nil
+  Tempfile.open("temp"){|fp|
+    fp.puts "hoge"
+    path = fp.path
+  }
+
+  system("cat #{path}")
+
+

Also available in: Atom PDF