Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > tempfileライブラリ > Tempfileクラス

class Tempfile

クラス・モジュールの継承リスト: Tempfile < Delegator < Object < Kernel < BasicObject

要約

テンポラリファイルを操作するためのクラスです。

特異メソッド

定義 説明
create(basename="", tmpdir=nil, mode: 0, **options) -> File
create(basename="", tmpdir=nil, mode: 0, **options) {|fp| ...} -> object

テンポラリファイルを作成し、それを表す File オブジェクトを生成して返します(Tempfileではありません)。 createはopenに似ていますが、finalizerによるファイルの自動unlinkを行いません。

new(basename = '', tempdir = nil, mode: 0, **options) -> Tempfile
open(basename = '', tempdir = nil, mode: 0, **options) -> Tempfile
open(basename = '', tempdir = nil, mode: 0, **options) {|fp| ...} -> object

テンポラリファイルを作成し、それを表す Tempfile オブジェクトを生成して返します。ファイル名のプレフィクスには指定された basename が使われます。ファイルは指定された tempdir に作られます。 open にブロックを指定して呼び出した場合は、Tempfile オブジェクトを引数として ブロックを実行します。ブロックの実行が終了すると、ファイルは自動的に クローズされ、ブロックの値をかえします。 new にブロックを指定した場合は無視されます。

インスタンスメソッド

定義 説明
close(real = false) -> nil

テンポラリファイルをクローズします。 real が偽ならば、テンポラリファイルはGCによって削除されます。そうでなければ、すぐに削除されます。

close! -> nil

テンポラリファイルをクローズし、すぐに削除します。

delete -> self
unlink -> self

テンポラリファイルをクローズせずに、削除します。 UNIXライクなシステムでは、作成したテンポラリファイルが他のプログラムに使用される機会をなくすために、テンポラリファイルを作成しオープンした後、すぐに削除するということがしばしばおこなわれます。

length -> Integer
size -> Integer

テンポラリファイルのサイズを返します。

open -> self

クローズしたテンポラリファイルを再オープンします。 "r+" でオープンされるので、クローズ前の内容を再度読むことができます。

path -> String | nil

テンポラリファイルのパス名を返します。

継承したメソッド

__id__ __send__ instance_eval instance_exec singleton_method_added singleton_method_removed singleton_method_undefined ! != == __getobj__ __setobj__ freeze marshal_dump marshal_load method_missing methods protected_methods public_methods respond_to? respond_to_missing? !~ <=> === =~ _dump class clone define_singleton_method display enum_for eql? equal? extend frozen? hash initialize initialize_copy inspect instance_of? instance_variable_defined? instance_variable_get instance_variable_set instance_variables is_a? itself method nil? object_id pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables private_methods psych_to_yaml public_method public_send remove_instance_variable send singleton_class singleton_method singleton_methods taint tainted? tap to_a to_ary to_hash to_int to_io to_proc to_regexp to_s to_str trust untaint untrust untrusted? yield_self .yaml_tag ::ARGF ::ARGV ::DATA ::ENV ::FALSE ::NIL ::RUBY_COPYRIGHT ::RUBY_DESCRIPTION ::RUBY_ENGINE ::RUBY_ENGINE_VERSION ::RUBY_PATCHLEVEL ::RUBY_PLATFORM ::RUBY_RELEASE_DATE ::RUBY_REVISION ::RUBY_VERSION ::SCRIPT_LINES__ ::STDERR ::STDIN ::STDOUT ::TOPLEVEL_BINDING ::TRUE