D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Tempfile
/
Filename :
new-c.ri
back
Copy
U:RDoc::AnyMethod[iI"new:ETI"Tempfile::new;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"3Creates a file in the underlying file system; ;TI"7returns a new \Tempfile object based on that file.;To:RDoc::Markup::BlankLine o; ; [I"@If possible, consider instead using Tempfile.create, which:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"0Avoids the performance cost of delegation, ;TI"Rincurred when Tempfile.new calls its superclass <tt>DelegateClass(File)</tt>.;To;;0; [o; ; [I"@Does not rely on a finalizer to close and unlink the file, ;TI"which can be unreliable.;T@o; ; [I"$Creates and returns file whose:;T@o;; ;;[ o;;0; [o; ; [I";Class is \Tempfile (not \File, as in Tempfile.create).;To;;0; [o; ; [I"DDirectory is the system temporary directory (system-dependent).;To;;0; [o; ; [I"4Generated filename is unique in that directory.;To;;0; [o; ; [I"$Permissions are <tt>0600</tt>; ;TI"<see {File Permissions}[rdoc-ref:File@File+Permissions].;To;;0; [o; ; [I"DMode is <tt>'w+'</tt> (read/write mode, positioned at the end).;T@o; ; [I"CThe underlying file is removed when the \Tempfile object dies ;TI"/and is reclaimed by the garbage collector.;T@o; ; [I" Example:;T@o:RDoc::Markup::Verbatim; [I"Cf = Tempfile.new # => #<Tempfile:/tmp/20220505-17839-1s0kt30> ;TI")f.class # => Tempfile ;TI">f.path # => "/tmp/20220505-17839-1s0kt30" ;TI")f.stat.mode.to_s(8) # => "100600" ;TI"%File.exist?(f.path) # => true ;TI"File.unlink(f.path) # ;TI"&File.exist?(f.path) # => false ;T:@format0o; ; [I"2Argument +basename+, if given, may be one of:;T@o;; ;;[o;;0; [o; ; [I"=A string: the generated filename begins with +basename+:;T@o;; [I"HTempfile.new('foo') # => #<Tempfile:/tmp/foo20220505-17839-1whk2f> ;T;0o;;0; [o; ; [I"8An array of two strings <tt>[prefix, suffix]</tt>: ;TI"Hthe generated filename begins with +prefix+ and ends with +suffix+:;T@o;; [I"STempfile.new(%w/foo .jpg/) # => #<Tempfile:/tmp/foo20220505-17839-58xtfi.jpg> ;T;0o; ; [I"WWith arguments +basename+ and +tmpdir+, the file is created in directory +tmpdir+:;T@o;; [I"JTempfile.new('foo', '.') # => #<Tempfile:./foo20220505-17839-xfstr8> ;T;0o; ; [I"JKeyword arguments +mode+ and +options+ are passed directly to method ;TI"%{File.open}[rdoc-ref:File.open]:;T@o;; ;;[o;;0; [o; ; [I"5The value given with +mode+ must be an integer, ;TI"Dand may be expressed as the logical OR of constants defined in ;TI"1{File::Constants}[rdoc-ref:File::Constants].;To;;0; [o; ; [I"AFor +options+, see {Open Options}[rdoc-ref:IO@Open+Options].;T@o; ; [I"Related: Tempfile.create.;T: @fileI"lib/tempfile.rb;T:0@omit_headings_from_table_of_contents_below000[ I"2(basename="", tmpdir=nil, mode: 0, **options);T@|TI" Tempfile;TcRDoc::NormalClass00