tags:

views:

30

answers:

2

File.open takes modes and options as arguments.

Where do I find a list of modes and options?

+2  A: 

In that Ruby IO module documentation, I suppose.

  Mode |  Meaning
  -----+--------------------------------------------------------
  "r"  |  Read-only, starts at beginning of file  (default mode).
  -----+--------------------------------------------------------
  "r+" |  Read-write, starts at beginning of file.
  -----+--------------------------------------------------------
  "w"  |  Write-only, truncates existing file
       |  to zero length or creates a new file for writing.
  -----+--------------------------------------------------------
  "w+" |  Read-write, truncates existing file to zero length
       |  or creates a new file for reading and writing.
  -----+--------------------------------------------------------
  "a"  |  Write-only, starts at end of file if file exists,
       |  otherwise creates a new file for writing.
  -----+--------------------------------------------------------
  "a+" |  Read-write, starts at end of file if file exists,
       |  otherwise creates a new file for reading and
       |  writing.
  -----+--------------------------------------------------------
   "b" |  (DOS/Windows only) Binary file mode (may appear with
       |  any of the key letters listed above).
floatless
Thanks for the list of the moes. But where are the list for the options: File.open(filename, mode="r" [, opt]) => file
never_had_a_name
Where did you find that? Unfortunately, I can't find `File.open(filename, mode="r" [, opt])` in the documentation.
floatless
@floatless. in the api for File class. Go to class "File" then click the method "open".
never_had_a_name
I suppose, it's some experimental, that is not implemented yet. And I still don't get about what API do you speak. Give a link.
Nakilon
I can see only `File.new(filename [, mode [, perm]]) => file` and the next comment: `Optional permission bits may be given in perm.`, so `File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)`. Huh? (Link: http://ruby-doc.org/core/classes/File.src/M002579.html)
floatless
@floatless: http://i53.tinypic.com/2nq9ji9.png
never_had_a_name
+1  A: 

opt is new for ruby 1.9. The various options are documented in IO.new : http://ruby-doc.org/ruby-1.9/classes/IO.html#M000131

Shadwell