Project

General

Profile

Bug #15411 ยป tempfile-docs.patch

zverok (Victor Shepelev), 12/13/2018 10:44 PM

View differences:

lib/tempfile.rb
47 47
#
48 48
#   file = Tempfile.new('foo')
49 49
#   begin
50
#      ...do something with file...
50
#      # ...do something with file...
51 51
#   ensure
52 52
#      file.close
53 53
#      file.unlink   # deletes the temp file
......
79 79
# same Tempfile object from multiple threads then you should protect it with a
80 80
# mutex.
81 81
class Tempfile < DelegateClass(File)
82
  # call-seq:
83
  #    new(basename = "", [tmpdir = Dir.tmpdir], [options])
84
  #
85 82
  # Creates a temporary file with permissions 0600 (= only readable and
86 83
  # writable by the owner) and opens it with mode "w+".
87 84
  #
......
114 111
  # +File.open+. This is mostly useful for specifying encoding
115 112
  # options, e.g.:
116 113
  #
117
  #   Tempfile.new('hello', '/home/aisaka', :encoding => 'ascii-8bit')
114
  #   Tempfile.new('hello', '/home/aisaka', encoding: 'ascii-8bit')
118 115
  #
119 116
  #   # You can also omit the 'tmpdir' parameter:
120
  #   Tempfile.new('hello', :encoding => 'ascii-8bit')
117
  #   Tempfile.new('hello', encoding: 'ascii-8bit')
118
  #
119
  # Note: +mode+ keyword argument, as accepted by Tempfile, can only be
120
  # numeric, combination of the modes defined in File::Constants.
121 121
  #
122 122
  # === Exceptions
123 123
  #
......
174 174
  #
175 175
  #   file = Tempfile.new('foo')
176 176
  #   begin
177
  #      ...do something with file...
177
  #      # ...do something with file...
178 178
  #   ensure
179 179
  #      file.close
180 180
  #      file.unlink   # deletes the temp file
......
195 195
  #   file = Tempfile.new('foo')
196 196
  #   file.unlink   # On Windows this silently fails.
197 197
  #   begin
198
  #      ... do something with file ...
198
  #      # ... do something with file ...
199 199
  #   ensure
200 200
  #      file.close!   # Closes the file handle. If the file wasn't unlinked
201 201
  #                    # because #unlink failed, then this method will attempt
......
277 277
    # In any case, all arguments (<code>*args</code>) will be passed to Tempfile.new.
278 278
    #
279 279
    #   Tempfile.open('foo', '/home/temp') do |f|
280
    #      ... do something with f ...
280
    #      # ... do something with f ...
281 281
    #   end
282 282
    #
283 283
    #   # Equivalent:
284 284
    #   f = Tempfile.open('foo', '/home/temp')
285 285
    #   begin
286
    #      ... do something with f ...
286
    #      # ... do something with f ...
287 287
    #   ensure
288 288
    #      f.close
289 289
    #   end
......
321 321
# <code>**options</code>) will be treated as Tempfile.new.
322 322
#
323 323
#   Tempfile.create('foo', '/home/temp') do |f|
324
#      ... do something with f ...
324
#      # ... do something with f ...
325 325
#   end
326 326
#
327 327
def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)