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: 2bc13c5a1792
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b3ac23c362f3
Choose a head ref
  • 3 commits
  • 2 files changed
  • 3 contributors

Commits on Mar 22, 2018

  1. Add Pathname#glob based on CRuby.

    This does not yet pass MRI Pathname#glob test.
    headius authored and nomadium committed Mar 22, 2018
    Copy the full SHA
    09e23c3 View commit details
  2. Update Pathname#glob implementation to pass MRI tests

    For more information, please see feature #7360.
    nomadium committed Mar 22, 2018
    Copy the full SHA
    37a70b6 View commit details

Commits on Mar 23, 2018

  1. Merge pull request #5105 from nomadium/add-pathname-glob-take-2

    Add Pathname#glob
    kares authored Mar 23, 2018
    Copy the full SHA
    b3ac23c View commit details
Showing with 46 additions and 12 deletions.
  1. +40 −12 core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
  2. +6 −0 core/src/main/java/org/jruby/runtime/JavaSites.java
52 changes: 40 additions & 12 deletions core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
Original file line number Diff line number Diff line change
@@ -30,22 +30,12 @@

import static org.jruby.anno.FrameField.BACKREF;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.*;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;

@JRubyClass(name = "Pathname")
@@ -371,6 +361,40 @@ public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObj
}
}

@JRubyMethod(required = 1, optional = 1)
public IRubyObject glob(ThreadContext context, IRubyObject[] _args, Block block) {
Ruby runtime = context.runtime;

IRubyObject[] args = new IRubyObject[3];
boolean blockGiven = block.isGiven();

args[0] = _args[0];
if (_args.length == 1) {
args[1] = RubyFixnum.zero(runtime);
} else {
args[1] = _args[1];
}

args[2] = RubyHash.newSmallHash(runtime);
((RubyHash) args[2]).fastASetSmall(runtime.newSymbol("base"), context.runtime.getFile().callMethod(context, "realpath", getPath()));

JavaSites.PathnameSites sites = sites(context);
CallSite glob = sites.glob;

RubyArray ary;
long i;
ary = glob.call(context, this, runtime.getDir(), args).convertToArray();
CallSite op_plus = sites.op_plus;
for (i = 0; i < ary.size(); i++) {
IRubyObject elt = ary.eltOk(i);
elt = op_plus.call(context, this, this, elt);
ary.eltSetOk(i, elt);
if (blockGiven) block.yield(context, elt);
}

return blockGiven ? context.nil : ary;
}

@JRubyMethod
public IRubyObject opendir(ThreadContext context, Block block) {
return context.runtime.getDir().callMethod(context, "open", new IRubyObject[] { getPath()},
@@ -445,4 +469,8 @@ private static RubyArray mapToPathnames(ThreadContext context, RubyClass clazz,
}
return paths;
}

private static JavaSites.PathnameSites sites(ThreadContext context) {
return context.sites.Pathname;
}
}
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ public class JavaSites {
public final ArgfSites Argf = new ArgfSites();
public final TracePointSites TracePoint = new TracePointSites();
public final MarshalSites Marshal = new MarshalSites();
public final PathnameSites Pathname = new PathnameSites();

public static class BasicObjectSites {
public final CallSite respond_to = new FunctionalCachingCallSite("respond_to?");
@@ -436,6 +437,11 @@ public static class MarshalSites {
public final RespondToCallSite respond_to_write = new RespondToCallSite("write");
}

public static class PathnameSites {
public final CallSite glob = new FunctionalCachingCallSite("glob");
public final CallSite op_plus = new FunctionalCachingCallSite("+");
}

public static class CheckedSites {
public final RespondToCallSite respond_to_X;
public final CachingCallSite respond_to_missing = new FunctionalCachingCallSite("respond_to_missing?");