Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4684 > unrolled thread

File.open options hash "mode" as int

Started byRoger Pack <rogerpack2005@gmail.com>
First post2011-05-17 13:22 -0500
Last post2011-05-19 15:16 -0500
Articles 7 — 3 participants

Back to article view | Back to comp.lang.ruby


Contents

  File.open options hash "mode" as int Roger Pack <rogerpack2005@gmail.com> - 2011-05-17 13:22 -0500
    Re: File.open options hash "mode" as int 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-17 13:49 -0500
      Re: File.open options hash "mode" as int Roger Pack <rogerpack2005@gmail.com> - 2011-05-17 14:28 -0500
        Re: File.open options hash "mode" as int 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-17 16:43 -0500
          Re: File.open options hash "mode" as int Roger Pack <rogerpack2005@gmail.com> - 2011-05-19 10:13 -0500
    Re: File.open options hash "mode" as int 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-19 12:41 -0500
      Re: File.open options hash "mode" as int Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-05-19 15:16 -0500

#4684 — File.open options hash "mode" as int

FromRoger Pack <rogerpack2005@gmail.com>
Date2011-05-17 13:22 -0500
SubjectFile.open options hash "mode" as int
Message-ID<3b31a717b9a883ae736dbcc1c08ad51e@ruby-forum.com>
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/.

[toc] | [next] | [standalone]


#4685

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-05-17 13:49 -0500
Message-ID<b085cd263884d6eeae5b4c5e0870b6e1@ruby-forum.com>
In reply to#4684
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/.

[toc] | [prev] | [next] | [standalone]


#4688

FromRoger Pack <rogerpack2005@gmail.com>
Date2011-05-17 14:28 -0500
Message-ID<59e82ce3f74c49b57360446162769a13@ruby-forum.com>
In reply to#4685
> 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/.

[toc] | [prev] | [next] | [standalone]


#4697

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-05-17 16:43 -0500
Message-ID<5972e92598eff180d6f8f1ed31683809@ruby-forum.com>
In reply to#4688
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/.

[toc] | [prev] | [next] | [standalone]


#4765

FromRoger Pack <rogerpack2005@gmail.com>
Date2011-05-19 10:13 -0500
Message-ID<53fd984f5bffbb0d6f70d06772856741@ruby-forum.com>
In reply to#4697
> 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/.

[toc] | [prev] | [next] | [standalone]


#4776

From7stud -- <bbxx789_05ss@yahoo.com>
Date2011-05-19 12:41 -0500
Message-ID<353acac0dfcecfcedccff382c326a23c@ruby-forum.com>
In reply to#4684
Don't get me started on how piss poor the ruby docs are.

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

[toc] | [prev] | [next] | [standalone]


#4784

FromPhillip Gawlowski <cmdjackryan@googlemail.com>
Date2011-05-19 15:16 -0500
Message-ID<BANLkTi=msyVj63zC6FvSV-Fs9dN4VK+7Kg@mail.gmail.com>
In reply to#4776
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.

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

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web