Project

General

Profile

Actions

Bug #20510

closed

File.open mode argument inconsistency

Added by akr (Akira Tanaka) 5 months ago. Updated 5 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:118015]

Description

I found that
File.new(1, mode: File::WRONLY, path: "foo") succeeds but
File.new(1, File::WRONLY, path: "foo") fails.

It is inconsistent.
I think they should both succeed.

% ./ruby -e 'p File.new(1, mode: File::WRONLY, path: "foo")'
#<File:foo>
% ./ruby -e 'p File.new(1, File::WRONLY, path: "foo")' 
-e:1:in 'File#initialize': no implicit conversion of Integer into String (TypeError)

p File.new(1, File::WRONLY, path: "foo")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	from -e:1:in 'IO.new'
	from -e:1:in '<main>'
% ./ruby -v                                           
ruby 3.4.0dev (2024-05-25T02:25:56Z tempfile-create-io 99463a8400) [x86_64-linux]

Updated by nobu (Nobuyoshi Nakada) 5 months ago ยท Edited

File.new(1, File::WRONLY) also succeeds.
https://github.com/ruby/ruby/pull/10844

Actions #2

Updated by nobu (Nobuyoshi Nakada) 5 months ago

  • Status changed from Open to Closed

Applied in changeset commit:git|0bae2f00025b6b51a9e0c9e3348d5f5d16c2aae4.


[Bug #20510] Do not count optional hash argument for IO.new

Since IO.new accepts one or two positional arguments except for the
optional hash argument, exclude the optional hash argument from the
check for delegation to IO.new.

Actions

Also available in: Atom PDF

Like0
Like0Like0