Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2689c3f9a8f1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e56ded21b6c1
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Nov 15, 2016

  1. Copy the full SHA
    85eec9f View commit details
  2. Merge pull request #4296 from kcdragon/md/feature/add-file-empty

    Add File.empty?
    enebo authored Nov 15, 2016
    Copy the full SHA
    e56ded2 View commit details
Showing with 18 additions and 0 deletions.
  1. +18 −0 core/src/main/java/org/jruby/RubyFile.java
18 changes: 18 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -784,6 +784,24 @@ public static String dirname(ThreadContext context, String jfilename) {
return result;
}

@JRubyMethod(name = {"empty?", "zero?"}, required = 1, meta = true)
public static IRubyObject empty(ThreadContext context, IRubyObject self, IRubyObject str) {
Ruby runtime = context.runtime;
String f = StringSupport.checkEmbeddedNulls(runtime, get_path(context, str)).getUnicodeValue();

if ( ! new File(f).exists() ) {
return runtime.getFalse();
}

int size = runtime.newFileStat(f, false).size().convertToInteger().getIntValue();
if (size == 0) {
return runtime.getTrue();
}
else {
return runtime.getFalse();
}
}

/**
* Returns the extension name of the file. An empty string is returned if
* the filename (not the entire path) starts or ends with a dot.