Skip to content

Commit a4e00cf

Browse files
committed
Allow File.open and File.new with 4 arguments
The methods now support filename, mode, permissions and options as separate parameters.
1 parent d507e49 commit a4e00cf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

core/src/main/java/org/jruby/RubyFile.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public IRubyObject flock(ThreadContext context, IRubyObject operation) {
321321
}
322322

323323
// rb_file_initialize
324-
@JRubyMethod(name = "initialize", required = 1, optional = 2, visibility = PRIVATE)
324+
@JRubyMethod(name = "initialize", required = 1, optional = 3, visibility = PRIVATE)
325325
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
326326
if (openFile != null) {
327327
throw context.runtime.newRuntimeError("reinitializing File");
@@ -1225,7 +1225,10 @@ protected IRubyObject openFile(ThreadContext context, IRubyObject args[]) {
12251225
break;
12261226
}
12271227
case 4:
1228-
options = args[3].convertToHash();
1228+
options = args[3];
1229+
if (!options.isNil() && !(options instanceof RubyHash)) {
1230+
throw runtime.newArgumentError("wrong number of arguments (4 for 1..3)");
1231+
}
12291232
vperm(pm, args[2]);
12301233
vmode(pm, args[1]);
12311234
break;

test/mri/excludes/TestPathname.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
exclude :test_find, "fails to EACCES an unreadable path, root cause of test_find.rb's test_unreadable_dir failure?"
22
exclude :test_lchmod, "fails on Travis, maybe on Linux in general?"
3-
exclude :test_open, "4-args open()"
43
exclude :test_realdirpath, "bad symlink resolution"
54
exclude :test_realpath, "needs investigation"
65
exclude :test_relative_path_from_casefold, "path encoding problems"

0 commit comments

Comments
 (0)