File.open options hash "mode" as int

Hello.
in 1.9.x, I see that these work:
File.open('yo', 'w')
File.open('yo', File::WRONLY|File::TRUNC|File::CREAT)
File.open('yo', :mode => 'w')

So shouldn't this also work?

File.open('yo', :mode => File::WRONLY|File::TRUNC|File::CREAT)

  TypeError: can't convert Fixnum into String

-roger-

···

--
Posted via http://www.ruby-forum.com/\.

Well, the docs say this:

···

===
IO.open(fd, mode_string="r" [, opt] ) → io
IO.open(fd, mode_string="r" [, opt] ) {|io| block } → obj

Document-method: IO::open

With no associated block, open is a synonym for IO.new.

===
IO.new(fd [, mode] [, opt]) → io

Returns a new IO object (a stream) for the given IO object or integer
file descriptor and mode string. See also IO.sysopen and IO.for_fd.
Parameters
fd: numeric file descriptor
mode: file mode. a string or an integer
opt: hash for specifying mode by name.

The last line there seems to be why you are getting the error.

--
Posted via http://www.ruby-forum.com/.

Don't get me started on how piss poor the ruby docs are.

···

--
Posted via http://www.ruby-forum.com/.

mode: file mode. a string or an integer

The last line there seems to explain why you are getting the error.
Although, you aren't supplying a *numeric* file descriptor either, so
who knows.

File::WRONLY|File::TRUNC|File::CREAT is numeric...

···

--
Posted via http://www.ruby-forum.com/\.

http://blog.steveklabnik.com/2011/05/10/contributing-to-ruby-s-documentation.html

···

On Thu, May 19, 2011 at 7:41 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:

Don't get me started on how piss poor the ruby docs are.

--
Phillip Gawlowski

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibnitz

Roger Pack wrote in post #999326:

mode: file mode. a string or an integer

The last line there seems to explain why you are getting the error.
Although, you aren't supplying a *numeric* file descriptor either, so
who knows.

File::WRONLY|File::TRUNC|File::CREAT is numeric...

...and what does the last line of the docs I posted say?

···

--
Posted via http://www.ruby-forum.com/\.

opt: hash for specifying mode by name.

I guess this is why. I just don't see quite *why* it requires mode by
name in opts, but accepts it by int when given as a parameter. But that
makes sense.

A few more notes.

IO.open(fd, mode_string="r" [, opt] ) → io

Yeah, interestingly, this doesn't look at all like
File.open('filename')
so...the docs just lack the most common usage of File.open apparently?
Odd.

···

--
Posted via http://www.ruby-forum.com/\.