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

Similar Threads

prob with File.open and perms 2
Chatbot 0
command line options hash 2
File Contents into Hash Table? 6
STDOUT to StringIO 2
regexp+hash problem 5
[ANN] JRuby 1.6.0.RC2 released 0
ANN main-4.4.0 0

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top