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: 4ad378dea62c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5fc4742afcbc
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 21, 2015

  1. Copy the full SHA
    62b4dbc View commit details
  2. Copy the full SHA
    d43ad7a View commit details
  3. Copy the full SHA
    5fc4742 View commit details
11 changes: 10 additions & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -81,7 +81,6 @@
import static org.jruby.RubyEnumerator.enumeratorize;
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.Helpers.memchr;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
import static org.jruby.runtime.invokedynamic.MethodNames.OP_CMP;
@@ -4097,6 +4096,16 @@ public RubyString pack(ThreadContext context, IRubyObject obj) {
}
}

@JRubyMethod(name = "dig", required = 1, rest = true)
public IRubyObject dig(ThreadContext context, IRubyObject[] args) {
return dig(context, args, 0);
}

final IRubyObject dig(ThreadContext context, IRubyObject[] args, int idx) {
final IRubyObject val = at( args[idx++] );
return idx == args.length ? val : RubyObject.dig(context, val, args, idx);
}

@Override
public Class getJavaClass() {
return List.class;
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1932,6 +1932,16 @@ public IRubyObject getIfNone(){
return ifNone;
}

@JRubyMethod(name = "dig", required = 1, rest = true)
public IRubyObject dig(ThreadContext context, IRubyObject[] args) {
return dig(context, args, 0);
}

final IRubyObject dig(ThreadContext context, IRubyObject[] args, int idx) {
final IRubyObject val = op_aref( context, args[idx++] );
return idx == args.length ? val : RubyObject.dig(context, val, args, idx);
}

private static class VisitorIOException extends RuntimeException {
VisitorIOException(Throwable cause) {
super(cause);
25 changes: 25 additions & 0 deletions core/src/main/java/org/jruby/RubyObject.java
Original file line number Diff line number Diff line change
@@ -537,6 +537,31 @@ public static RubyString inspect(ThreadContext context, IRubyObject object) {
return str;
}

// MRI: rb_obj_dig
static IRubyObject dig(ThreadContext context, IRubyObject obj, IRubyObject[] args, int idx) {
if ( obj.isNil() ) return context.nil;
if ( obj instanceof RubyArray ) {
return ((RubyArray) obj).dig(context, args, idx);
}
if ( obj instanceof RubyHash ) {
return ((RubyHash) obj).dig(context, args, idx);
}
if ( obj.respondsTo("dig") ) {
final int len = args.length - idx;
switch ( len ) {
case 1:
return obj.callMethod(context, "dig", args[idx]);
case 2:
return obj.callMethod(context, "dig", new IRubyObject[] { args[idx], args[idx+1] });
default:
IRubyObject[] rest = new IRubyObject[len];
System.arraycopy(args, idx, rest, 0, len);
return obj.callMethod(context, "dig", rest);
}
}
return context.nil; // can not dig further (there's still args left)
}

/**
* Tries to support Java serialization of Ruby objects. This is
* still experimental and might not work.
3 changes: 3 additions & 0 deletions spec/truffle/tags/core/array/dig_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:Array#dig returns #at with one arg
fails:Array#dig recurses array elements
fails:Array#dig raises without any args
4 changes: 4 additions & 0 deletions spec/truffle/tags/core/hash/dig_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fails:Hash#dig returns [] with one arg
fails:Hash#dig does recurse
fails:Hash#dig raises without args
fails:Hash#dig handles type-mixed deep digging