|
30 | 30 |
|
31 | 31 | import static org.jruby.anno.FrameField.BACKREF;
|
32 | 32 |
|
33 |
| -import org.jruby.Ruby; |
34 |
| -import org.jruby.RubyArray; |
35 |
| -import org.jruby.RubyClass; |
36 |
| -import org.jruby.RubyFixnum; |
37 |
| -import org.jruby.RubyModule; |
38 |
| -import org.jruby.RubyObject; |
39 |
| -import org.jruby.RubyString; |
| 33 | +import org.jruby.*; |
40 | 34 | import org.jruby.anno.JRubyClass;
|
41 | 35 | import org.jruby.anno.JRubyMethod;
|
42 | 36 | import org.jruby.exceptions.RaiseException;
|
43 | 37 | import org.jruby.internal.runtime.methods.JavaMethod;
|
44 |
| -import org.jruby.runtime.Block; |
45 |
| -import org.jruby.runtime.Helpers; |
46 |
| -import org.jruby.runtime.ObjectAllocator; |
47 |
| -import org.jruby.runtime.ThreadContext; |
48 |
| -import org.jruby.runtime.Visibility; |
| 38 | +import org.jruby.runtime.*; |
49 | 39 | import org.jruby.runtime.builtin.IRubyObject;
|
50 | 40 |
|
51 | 41 | @JRubyClass(name = "Pathname")
|
@@ -371,6 +361,41 @@ public static IRubyObject glob(ThreadContext context, IRubyObject recv, IRubyObj
|
371 | 361 | }
|
372 | 362 | }
|
373 | 363 |
|
| 364 | + @JRubyMethod(required = 1, optional = 1) |
| 365 | + public IRubyObject glob(ThreadContext context, IRubyObject[] _args, Block block) { |
| 366 | + Ruby runtime = context.runtime; |
| 367 | + |
| 368 | + IRubyObject[] args = new IRubyObject[3]; |
| 369 | + |
| 370 | + args[0] = _args[0]; |
| 371 | + if (_args.length == 1) { |
| 372 | + args[1] = RubyFixnum.zero(runtime); |
| 373 | + } else { |
| 374 | + args[1] = _args[1]; |
| 375 | + } |
| 376 | + |
| 377 | + args[2] = RubyHash.newSmallHash(runtime); |
| 378 | + ((RubyHash) args[2]).fastASetSmall(runtime.newSymbol("base"), getPath()); |
| 379 | + |
| 380 | + JavaSites.PathnameSites sites = sites(context); |
| 381 | + CallSite glob = sites.glob; |
| 382 | + |
| 383 | + if (block.isGiven()) { |
| 384 | + return glob.call(context, this, runtime.getDir(), args, block); |
| 385 | + } else { |
| 386 | + RubyArray ary; |
| 387 | + long i; |
| 388 | + ary = glob.call(context, this, runtime.getDir(), args).convertToArray(); |
| 389 | + CallSite op_plus = sites.op_plus; |
| 390 | + for (i = 0; i < ary.size(); i++) { |
| 391 | + IRubyObject elt = ary.eltOk(i); |
| 392 | + elt = op_plus.call(context, this, this, elt); |
| 393 | + ary.eltSetOk(i, elt); |
| 394 | + } |
| 395 | + return ary; |
| 396 | + } |
| 397 | + } |
| 398 | + |
374 | 399 | @JRubyMethod
|
375 | 400 | public IRubyObject opendir(ThreadContext context, Block block) {
|
376 | 401 | return context.runtime.getDir().callMethod(context, "open", new IRubyObject[] { getPath()},
|
@@ -445,4 +470,8 @@ private static RubyArray mapToPathnames(ThreadContext context, RubyClass clazz,
|
445 | 470 | }
|
446 | 471 | return paths;
|
447 | 472 | }
|
| 473 | + |
| 474 | + private static JavaSites.PathnameSites sites(ThreadContext context) { |
| 475 | + return context.sites.Pathname; |
| 476 | + } |
448 | 477 | }
|
0 commit comments