Skip to content

Commit

Permalink
make RubyDir implement Closeable (to align with RubyFile)
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Jun 8, 2018
1 parent 8d73b22 commit 6562738
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/main/java/org/jruby/RubyDir.java
Expand Up @@ -32,6 +32,7 @@

package org.jruby;

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -69,7 +70,7 @@
* @author jvoegele
*/
@JRubyClass(name = "Dir", include = "Enumerable")
public class RubyDir extends RubyObject {
public class RubyDir extends RubyObject implements Closeable {
private RubyString path; // What we passed to the constructor for method 'path'
protected FileResource dir;
private long lastModified = Long.MIN_VALUE;
Expand Down Expand Up @@ -649,13 +650,15 @@ public static IRubyObject open19(ThreadContext context, IRubyObject recv, IRubyO
* Closes the directory stream.
*/
@JRubyMethod(name = "close")
public IRubyObject close() {
public IRubyObject close(ThreadContext context) {
close();
return context.nil;
}

public final void close() {
// Make sure any read()s after close fail.
checkDirIgnoreClosed();

isOpen = false;

return getRuntime().getNil();
}

/**
Expand Down

0 comments on commit 6562738

Please sign in to comment.