File.open options hash "mode" as int

R

Roger Pack

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?
TypeError: can't convert Fixnum into String

-roger-
 
7

7stud --

Well, the docs say this:

=3D=3D=3D
Io_Open(fd, mode_string=3D"r" [, opt] ) =E2=86=92 io
Io_Open(fd, mode_string=3D"r" [, opt] ) {|io| block } =E2=86=92 obj

Document-method: IO::eek:pen

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

=3D=3D=3D
IO.new(fd [, mode] [, opt]) =E2=86=92 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.
=3D=3D=3D

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

-- =

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

Roger Pack

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...
 
R

Roger Pack

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=3D"r" [, opt] ) =E2=86=92 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/.=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top